How can I check a method is called with a specific parameter on a mock object?
Can you help to achieve the goal I mentioned in the commented block below to complete sample unit test?
Idea is how to check on a mock object, if one of its methods is called with a type instance that has a particular property is set to expected value/
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"
开发者_开发问答}
I think you're looking for argument constraints in Rhino Mocks. I had a go at a few of the frameworks sometime ago - link. I think you're looking for
Arg<IViewModel>.Matches (vm => vm.Person.Name == "Peter" )
Look at the reference:
stub.AsswertWasCalled(s=>s.Render(Arg<IViewModel>.Property("Person", "John")))
精彩评论