最小起订量 - 如何验证方法还没有被调用,如果类吞下例外 [英] moq - how to verify method has not been called if the class swallows exceptions

查看:110
本文介绍了最小起订量 - 如何验证方法还没有被调用,如果类吞下例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用起订量来测试一个相当复杂的阶级和我遇到了一个问题。

I am trying to test a fairly complex class using Moq and am running into a problem.

我想验证一个方法不会被调用,并通常这是简单的设置MockBehavior.Strict做的,但在这里却班里有它自己的错误报告机制,因此由燕子所起订量抛出的异常。

I am trying to verify that a method does NOT get called, and usually this is simple to do by setting MockBehavior.Strict, but here however the class has its own error reporting mechanism so it swallows the exception being thrown by Moq.

.VerifyAll在试验结束方法也通过罚款,这是很奇怪。这是起订量的错误,是否有任何变通办法?

.VerifyAll method at the end of the test also passes fine, which is really weird. Is this a bug in Moq, are there any workarounds?

我也试过这种方法建立的回调,做Assert.Fail它内部的,但由于这个被吞噬还有,测试框架(VS 2008内置的测试)...

I've also tried setting up a callback on this method and doing Assert.Fail inside of it, but as this gets swallowed as well, the testing framework (VS 2008 builtin test) doesn't get notified of it...

我用的起订量2.6.1014.1没有得到通知的。 (没有时间升级到3起订量还)

I am using Moq 2.6.1014.1. (didn't have time to upgrade to moq 3 yet)

推荐答案

那么,这是令人尴尬的,我已经成功地解决它。

Well, this is embarrassing, I've managed to solve it.

在3.0,你可以这样做:

In 3.0 you can do this:

mFMXmlC.Verify(f=>f.Put_Queue_Response(It.IsAny<Uri>(), 
                                       It.IsAny<string>(), 
                                       It.IsAny<string>(), 
                                       It.IsAny<object>()), Times.Never());



还是不明白,为什么 VerifyAll 没'T的工作,但是这似乎无论如何适应该法案。我会离开的问题了,以防别人正在寻找类似的东西。

Still don't understand why VerifyAll didn't work, but this seems to fit the bill anyway. I'll leave the question up, in case someone else is looking for something similar.

这篇关于最小起订量 - 如何验证方法还没有被调用,如果类吞下例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆