Moq.Linq.MockRepository 是做什么的?

发布于 2024-11-02 18:29:40 字数 174 浏览 0 评论 0原文

我想弄清楚 MockRepository 是做什么的。
我看到有一个我理解的 Create 方法,它也有我不理解的 Of 和 OneOf 方法。
T 应该是什么?模拟还是 T 本身?
表情应该是什么样的?是设置表达式吗?
我在这里到底要查询什么?这只是创建模拟的另一种方式还是跟踪现有的模拟并获取它们?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转瞬即逝 2024-11-09 18:29:40

我认为它用于允许更轻松地验证多个模拟(来自起订量文档):

        var mockRepo = new Moq.MockRepository(MockBehavior.Default);
        var foo = mockRepo.Create<IFoo>();
        var bar = mockRepo.Create<IBar>();

在任何情况下设置模拟并练习模拟

        mockRepo.VerifyAll();

,您想用这个类完成什么?

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?

微凉 2024-11-09 18:29:40

我在使用 MockRepository 时也遇到了问题。也许我对课程有概念上的误解。我对 MockRepository 的看法是,它创建了类似于模拟模板实例的东西。

要使用示例接口,假设 IFoo 有多个属性和方法。我想在测试夹具级别设置一个模板模拟实例,该实例为每个属性和方法提供一些合理的默认返回值。然后,在每个测试方法中,用适合当前测试的值覆盖这些值。这样就不必在每个测试中设置每个 IFoo 模拟。

在之前的项目中,我编写了自己的模拟工厂类来执行此操作,但 MockRepository 的描述听起来像是同一件事。

我是否误解了MockRepository?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文