如何检查模拟对象上特定参数的方法?
问题描述:
您是否可以帮助实现我在下面的注释块中提到的目标以完成样品单元测试?如何检查模拟对象上特定参数的方法?
想法是如何/检查模拟对象上,如果它的一个方法被调用,具有特定属性设置为预期值的类型实例
private IMyObject stub = MockRepository.GenerateMock<IMyObject>();
[TestMethod]
public void MakeMyJob_RecievesValidData_CallsRenderWithCorrectParameter()
{
SomeUtility.MakeMyJob(5,10,stub);
stub.AsswertWasCalled(s=>s.Render(Arg<IViewModel>.Is. //What next?
// In order to check if Render is called
// with a IViewModel instance
// whoose Person.Name property is "Peter"
}
答
看:
stub.AsswertWasCalled(s=>s.Render(Arg<IViewModel>.Property("Person", "John")))
更好的链路 - http://ayende.com/wiki/Rhino+Mocks+3.5.ashx#ArgumentConstraints。查找名为“复杂表达式”的部分 – Gishu