I am trying to figure out what does the MockRepository do.
I see that there is a Create method which I understand and it also has Of and OneOf methods which I don't understand.
What should T be? Mock or T itself?
How should the expression look like? Is it the setup expression?
What exactly am I querying here? Is it just another way to create a mock or does it track existing mocks and fetches them?
I think it is used to allow easier verification of multiple mocks (from the moq docs -sort of):
var mockRepo = new Moq.MockRepository(MockBehavior.Default);
var foo = mockRepo.Create<IFoo>();
var bar = mockRepo.Create<IBar>();
set up mocks and excercise the mocks
mockRepo.VerifyAll();
in any case, what are you trying to accomplish with this class?
I'm having trouble with MockRepository,
too. Perhaps I have a conceptual misunderstanding of the class. My view of MockRepository
is that it creates something akin to template instances of a mock.
To use the example interfaces, suppose IFoo
had several properties and methods on it. I'd like to setup a template mock instance at the test fixture level that has some reasonable default return value for each property and method. Then, in each test method, override those values with values appropriate for the test at hand. This saves having to setup each IFoo
mock in every test.
In a previous project, I wrote my own mock factory class that did this, but the description of MockRepository
sounds like the same thing.
Am I misunderstanding MockRepository?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With