Moq.Linq.MockRepository 是做什么的?
我想弄清楚 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为它用于允许更轻松地验证多个模拟(来自起订量文档):
在任何情况下设置模拟并练习模拟
,您想用这个类完成什么?
I think it is used to allow easier verification of multiple mocks (from the moq docs -sort of):
set up mocks and excercise the mocks
in any case, what are you trying to accomplish with this class?
我在使用
MockRepository
时也遇到了问题。也许我对课程有概念上的误解。我对 MockRepository 的看法是,它创建了类似于模拟模板实例的东西。要使用示例接口,假设 IFoo 有多个属性和方法。我想在测试夹具级别设置一个模板模拟实例,该实例为每个属性和方法提供一些合理的默认返回值。然后,在每个测试方法中,用适合当前测试的值覆盖这些值。这样就不必在每个测试中设置每个
IFoo
模拟。在之前的项目中,我编写了自己的模拟工厂类来执行此操作,但
MockRepository
的描述听起来像是同一件事。我是否误解了
MockRepository?
I'm having trouble with
MockRepository,
too. Perhaps I have a conceptual misunderstanding of the class. My view ofMockRepository
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 eachIFoo
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?