MOQ – verify exception was thrown

If you want to verify an exception was thrown (by your own code) then Moq is not your tool of choice for that.
Simply use one of the unit test frameworks available.

Xunit/NUnit:

Assert.Throws<SomeException>(() => foo.Bar());

Fluent Assertions:

Action act = () => foo.Bar();
act.Should().Throw<SomeException>();
               

https://fluentassertions.com/introduction

http://www.nunit.org/index.php?p=exceptionAsserts&r=2.6.2

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)