Rhino Mocks - 如何断言被调用 n 次的模拟方法? [英] Rhino Mocks - How to assert a mocked method was called n-times?

查看:37
本文介绍了Rhino Mocks - 如何断言被调用 n 次的模拟方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何断言模拟对象上的方法被精确调用了 n 次?

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);
}

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

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)

推荐答案

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

这篇关于Rhino Mocks - 如何断言被调用 n 次的模拟方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆