开发者

What does Moq.Linq.MockRepository do?

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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜