The following Func delegate throws an ArgumentNullException:
Func<Task> act = async () => await _someService
.someMethod(1, 2, 3, 4);
Using Fluent assertions, the assertion:
act.Should().ThrowExactlyAsync<ArgumentException>();
Should fail:
Asserts that the current
Functhrows an exception of the exact typeTException(and not a derived exception type).
ArgumentNullException derives from ArgumentException, given the description, the assertion should fail, but it passes.
Is it a bug or am I misusing this?
Since ThrowExactlyAsync returns a Task, you're not actually doing anything unless you await it:
await act.Should().ThrowExactlyAsync<ArgumentException>();
Replace act.Should().ThrowExactlyAsync<ArgumentException>();
with await act.Should().ThrowExactlyAsync<ArgumentException>();\
This will give you a correct result (fail in this case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With