Reputation: 1547
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 help.
Upvotes: 0
Views: 1818
Reputation: 84734
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);
Upvotes: 1
Reputation: 14677
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.
Upvotes: 1