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

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -