I'm using NUnit 3 TestCaseData
objects to feed test data to tests and Fluent Assertions library to check exceptions thrown.
Typically my TestCaseData
object contains two parameters param1
and param2
used to create an instance of some object within the test and upon which I then invoke methods that should/should not throw exceptions, like this:
var subject = new Subject(param1, param2);
subject.Invoking(s => s.Add()).Should().NotThrow();
or
var subject = new Subject(param1, param2);
subject.Invoking(s => s.Add()).Should().Throw<ApplicationException>();
Is there a way to pass NotThrow()
and Throw<ApplicationException>()
parts as specific conditions in a third parameter in TestCaseData
object to be used in the test? Basically I want to parameterize the test's expected result (it may be an exception of some type or no exception at all).