Testing Exception Messages with Shouldly
Solution 1:
The Should.Throw()
method returns the exception, so you can continue to test if for other things.
For example:
Should.Throw<MyException>(() => new ClassUnderTest().DoSomething())
.Message.ShouldBe("My Custom Message");
Or, if you want to do more than just test the message:
MyException ex = Should.Throw<MyException>(() => new ClassUnderTest().DoSomething());
You can then do what you like with ex
.
Note: Shouldly V2 uses Should.ThrowException<>()