Assert.Throws overloads for message verification and additional matching with expression
weitzhandler opened this issue · 2 comments
weitzhandler commented
Hi,
Currently, Assert.Throws
provides some overloads for ArgumentException.ParamName
matching and a few other overloads.
My suggestion is for another overload to be added with an exception matcher expression overload, for flexible and customizable exception verification.
For example:
var expectedExceptionMessage = "My exception message";
var expectedException = new MyServiceException(expectedExceptionMessage);
Assert.Throws(expectedException, () => myService.DoJob());
// or
Assert.Throws(exception => exception.Message == expectedExceptionMessage);
Here are another couple of overloads I'd like to see (same for async and "Any" when applicable):
Assert.Throws(string message, Action testCode);
Assert.Throws(string message, string paramName, Action testCode);
I'm willing to implement this.
stakx commented
The Assert
class is not part of Moq, I guess you're talking about the class from your testing framework of choice (xUnit)? You should perhaps ask at their repository.
weitzhandler commented
Oops 😳 sorry.