我使用 RhinoMocks 毫无问题地使用 AssertWasCalled 检查我的方法是否使用简单的参数调用,例如 Arg.Is.Equal(1) 等。
但是,当我尝试期待自己创建的复杂对象时,它失败了,例如
Arg<CustomClass>.Is.Equal(CustomClassInstance)
当然,我很清楚这应该行不通,因为引用不匹配。但是,我的问题是:如何让它发挥作用?如何让 RhinoMocks 期待一个内部有特定值的对象?
最佳答案
您可以使用 Arg<T>.Matches (Predicate<T> predicate)
喜欢:
mock.AssertWasCalled (m => m.Foo (Arg<CustomClass>.Matches (c => c.Foo == CustomClassInstance.Foo));
关于c# - RhinoMocks 期望复杂对象作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5385793/