开发者

How can I check a method is called with a specific parameter on a mock object?

开发者 https://www.devze.com 2023-04-12 03:32 出处:网络
Can you help to achieve the goal I mentioned in the commented block below to complete sample unit test?

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")))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号