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

邮差的信 提交于 2019-12-08 14:48:31

问题


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)


回答1:


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




回答2:


better yet:

mockObject.AssertWasCalled(x => x.SomeMethod(), opt => opt.Repeat.Times(n));


来源:https://stackoverflow.com/questions/642801/rhino-mocks-how-to-assert-a-mocked-method-was-called-n-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!