Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks - How to assert a mocked method was called n-times?

How can i assert that a method on a mocked object was called exactly called n-times?

Here is the code snippet from a controller action, i like to test:

for (int i = 0; i <= newMatchCommand.NumberOfMatchesToCreate; i++) {
    serviceFacade.CreateNewMatch("tester", Side.White);
}

The "service facade" object is the (strict) mock and will be injected into the controller. The unit test should assert that the CreateNewMatch method within the action was called n-times. (e.g. 5)

like image 626
Michael Wallasch Avatar asked Mar 13 '09 13:03

Michael Wallasch


2 Answers

better yet:

mockObject.AssertWasCalled(x => x.SomeMethod(), opt => opt.Repeat.Times(n));
like image 150
Matt Hinze Avatar answered Nov 09 '22 11:11

Matt Hinze


Try Expect.Call(method).Repeat.Times(n).

like image 44
Brandon Avatar answered Nov 09 '22 12:11

Brandon