有没有? :
var storage = mocks.DynamicMock<IStorage>();
...
SetupResult.For(storage.GetCustomers())
.Return(new Collection<Customer> { cust1, cust2 });
// and
storage.Stub(x => x.Customers)
.Return(new Collection<Customer> { cust1, cust2 });
最佳答案
编辑:我之前没有看到Stub
扩展方法,只看到存储库上的方法。
我怀疑主要区别在于当模拟处于任一模式(回放或记录)时,您可以调用 Stub
。它会暂时将其设置回记录模式,记录操作,然后如果它在回放模式下开始则恢复回放。
它还允许您在一个 lambda 表达式中 stub 多个操作,只要您只需要其中一个操作(最后一个)返回结果即可。
关于c# - RhinoMocks 中的 SetupResult 和 Stub 有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/881084/