最小起订量 测试返回类型
鉴于以下情况:
var mockIActionService = new Mock<IActionService>();
var mockValidAgeRule = new Mock<ValidAgeRule>(mockIActionService.Object);
mockValidAgeRule.Setup(t => t.Execute(app));
现在 t.Execute 返回一个“Rules”对象,我如何验证是否已在 Rules 上调用了某些内容?
我试图这样称呼它 mockValidAgeRule.Verify(x => x.Execute(app).Passed)
我想测试给定输入的对象 Result 返回 true 。
对于所有问题,我们深表歉意,只是我在查找有关最小起订量的最新且有帮助的信息时遇到了一些困难
Given the following:
var mockIActionService = new Mock<IActionService>();
var mockValidAgeRule = new Mock<ValidAgeRule>(mockIActionService.Object);
mockValidAgeRule.Setup(t => t.Execute(app));
Now t.Execute returns a "Rules" object, how can I verify that something has been called on Rules?
I am attempting to call it as such mockValidAgeRule.Verify(x => x.Execute(app).Passed)
I want to test that the object Result returned true given the inputs.
Sorry for all questions just am having a little trouble finding info about MOQ that is up to date and helpful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,正如克里斯所说,您没有提供足够的细节来获得正确的答案。尽管如此,恕我直言,很明显这个测试有代码味道。它似乎没有任何具体的实现。完全由模拟对象组成的测试不太可能测试任何有用的东西。
哪个类代表您的 SUT?听起来它可能是您的规则对象。如果您提供有关对象模型和预期行为的更多详细信息,则提供反馈会更容易。
Well, as stated by Chris, you haven't provided enough detail to get a proper answer. Nonetheless, IMHO it's pretty clear that this test has a code smell. It don't appear to have any concrete implementations. A test completely composed of mock objects is not likely testing anything useful.
Which class represents your SUT? It sounds like it might be your Rules object. If you provide further detail about your object model and expected behaviors, it would be easier to provide a feedback.
我建议添加 RulesMock 对象,如下所示:
然后将此模拟添加到您的代码中:
因此,如果您的 Rules getter 调用 MethodInRules(),您可以检查它的调用方式:
这是一个想法,希望这对某人有帮助,祝您好运!
I suggest to add RulesMock object something like this:
then add this mock to your code:
so, if your Rules getter call MethodInRules() you can check this is called by:
It is an idea, hope this helps someone, good luck!