Rhino Mocks - How to assert a mocked method was ca

2019-06-15 00:37发布

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)

2条回答
仙女界的扛把子
2楼-- · 2019-06-15 01:01

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

查看更多
Melony?
3楼-- · 2019-06-15 01:09

better yet:

mockObject.AssertWasCalled(x => x.SomeMethod(), opt => opt.Repeat.Times(n));
查看更多
登录 后发表回答