c# - Xunit.net and Moq Assert that method is called regardless of an exception being thrown -
in method i'm testing want assert call has been made before exception thrown.
currently act/assert section of test looks this:
assert.throws<exception>(() => sut.handlemessage(messagetoprocess)); mock.verify(n => n.method(it.isany<string>()), times.once);
but breaks rule of asserting once since i'm asserting handlemessage
throws exception (which has own test case) , verifying mock.method
called.
means test fails if exception hasn't been thrown isn't i'm testing here.
how verify method has been called if exception hasn't been thrown, try-catch-finally acceptable here (as below)?
try { sut.handlemessage(messagetoprocess); } catch{} { mock.verify(n => n.method(it.isany<string>()), times.once); }
Comments
Post a Comment