Mock.assertMethodCalls

Assert all replaced methods are called the defined amount of times.

class Mock(C)
void
assertMethodCalls
(
string message = "Failed asserting call count"
,
string file = __FILE__
,
size_t line = __LINE__
)
if (
is(C == class) ||
is(C == interface)
)

Parameters

message
Type: string

The error message to display.

file
Type: string

The file name where the error occurred. The value is added automatically at the call site.

line
Type: size_t

The line where the error occurred. The value is added automatically at the call site.

Throws

DUnitAssertError if any method was called outside of preset boundries.

Examples

1 import dunit.mockable;
2 
3 class T
4 {
5    int getValue()
6    {
7        return 1;
8    }
9 
10    mixin Mockable!(T);
11 }
12 
13 unittest
14 {
15    import dunit.toolkit;
16 
17    auto mock = T.getMock();
18 
19    // Replace method while defining a minimum call limit.
20    mock.mockMethod("getValue", delegate(){
21        return 2;
22    }, 1);
23 
24    // Increase the call count of 'getValue' by one.
25    mock.getValue().assertEqual(2);
26 
27    // Assert methods calls are within defined limits.
28    mock.assertMethodCalls();
29 }

Meta