Rhino Mocks - 如何断言一个模拟方法被称为n次?

Her*_* W. 15 tdd unit-testing rhino-mocks

我如何断言模拟对象上的方法被称为n次?

这是控制器动作的代码片段,我想测试:

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

"服务外观"对象是(严格)模拟,将被注入控制器.单元测试应断言操作中的CreateNewMatch方法被调用n次.(例如5)

Mat*_*nze 42

更好的是:

mockObject.AssertWasCalled(x => x.SomeMethod(), opt => opt.Repeat.Times(n));
Run Code Online (Sandbox Code Playgroud)


Bra*_*don 5

尝试Expect.Call(method).Repeat.Times(n)