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

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -