MockCommon.expectCalled

Used to assert function call many counts

  1. void expectCalled(auto ref V values)
  2. void expectCalled(auto ref V values)
    mixin template MockCommon()
    void
    expectCalled
    (
    string functionName
    ulong count
    string message = null
    string file = __FILE__
    size_t line = __LINE__
    V...
    )
    (
    auto ref V values
    )

Parameters

functionName

The name of expected function.

count

Count of calls.

message

Exception message.

file

The file name that the assert failed in. Should be left as default.

line

The file line that the assert failed in. Should be left as default.

values
Type: V

Are expected parameter values.

Throws

If function is not call many count with parameters, will throw an UnitTestException.

Examples

1 interface Dummy
2 {
3   void test();
4   void test(int a);
5 }
6 
7 auto mock = new Mock!Dummy;
8 mock.test();
9 mock.test(12);
10 mock.expectCalled!("test", 1)();
11 mock.expectCalled!("test", 1)(12);
12 
13 // Will throw an exception like "UnitTestException@example.d(6): <test> expected call with <12> <2> count but called <1> counts
14 mock.exceptCalled!("test", 2)(12);

Meta