Invoking() should allow null subjects #1732
-
DescriptionAs per 15c20b3 the Invoking() methods are rejecting null subjects. While I fully agree with the check for the action, I feel that a null subject should be valid. E.g. this seems a sensible test to write: public static void ThrowOnNull(object? arg)
{
if (arg == null)
throw new ArgumentNullException(nameof(arg));
}
[Fact]
public void ThrowsOnNull()
{
object? arg = null;
arg.Invoking(x => ThrowOnNull(x))
.Should()
.Throw<ArgumentNullException>();
} Expected behavior:The above test should succeed. Actual behavior:Currently this test fails, with an System.ArgumentNullException from within FluentAssertions. VersionsFluentAssertions 6.2.0 |
Beta Was this translation helpful? Give feedback.
Answered by
dennisdoomen
Nov 5, 2021
Replies: 1 comment 1 reply
-
The intention of Action act = () => ThrowOnNull(arg);
act.Should().Throw<ArgumentNullException>(); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jnyrup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The intention of
Invoking
is to invoke members of the subject-under-test. So we don't expect the subject itself to ever benull
. But you can rewrite this as: