ASP.Net MVC - Rhino Mocks - Expected method call parameters
I am setting a expectation on a method which has a object as the parameter. This object will be created inside the called functionality. When I mock this I get an error saying Expected #1 Actual #0
How to resolve this ?
Code:
Customer testObject = new Customer(); Expect.Call(sampleRepository.Find(testObject)).Return(True);
I am suspecting creating a new object makes this expectation fail.
Please he开发者_如何学Pythonlp.
Use the "IgnoreArguments" method:
Customer testObject = new Customer(); Expect.Call(sampleRepository.Find(testObject)).IgnoreArguments().Return(True);
This tells Rhino.Mocks to just expect a call on "Find" and you don't care what the parameters are.
In additional to Patrick's answer, you can use Constraints()
to check properties on the object without having to check the object instance itself. Each argument to Constraints
is the constraint for the actual argument at that position (you can use &&
or ||
to multiple constraints to combine them):
Customer testObject = new Customer();
Expect.Call(sampleRepository.Find(testObject))
.Constraints(
Is.NotNull() && Property.Value("Nickname", "SnakeEyes")
)
.Return(True);
精彩评论