Moq - the verification method is not called if the class swallows exceptions

I am trying to test a rather complex class using Moq, and I ran into a problem.

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

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

I also tried setting up a callback to this method and executing Assert.Fail inside it, but as it is swallowed, the test environment (VS 2008 built-in test) does not receive notifications about it ..

I am using Moq 2.6.1014.1. (not yet managed to upgrade to moka 3)

+6
c # unit-testing moq
source share
1 answer

Well, that’s awkward, I managed to solve it.

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()); 

Still don't understand why VerifyAll didn't work, but it seems to match the score anyway. I will leave a question if someone is looking for something like that.

+11
source share

All Articles