Argument constraints in RhinoMock methods

Posted by Khash on Stack Overflow See other posts from Stack Overflow or by Khash
Published on 2010-03-19T11:48:23Z Indexed on 2010/03/19 11:51 UTC
Read the original article Hit count: 220

Filed under:
|

I am mocking a repository that should have 1 entity in it for the test scenario. The repository has to return this entity based on a known id and return nothing when other ids are passed in.

I have tried doing something like this:

_myRepository.Expect(item => item.Find(knownId)).Return(knownEntity);
_myRepository.Expect(item => item.Find(Arg<Guid>.Is.Anything)).Return(null);

It seems however the second line is overriding the first and the repository always returns null. I don't want to mock all the different possible IDs asked (they could go up to hundreds) when the test scenario is only concerned with the value of one Id.

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about rhino-mocks