Reputation: 6608
I am trying to use the Fluent Assertions ShouldBeNull() extension method to assert that my instance is indeed null.
Result.ShouldBeNull();
Clearly, this throws an exception because I cannot call the extension on a null instance.
System.NullReferenceException
How do I use Fluent Assertions properly to make this assertion?
Upvotes: 2
Views: 1431
Reputation: 1
Result needs to be nullable
result?.Should().BeNull();
Even if you're checking for null, you're still trying to do an operation on a null value.
Upvotes: -1
Reputation: 8899
I wonder if you actually used FluentAssertions, because then your call should have looked like:
Result.Should().BeNull()
So with the dot .
Upvotes: 0
Reputation: 40566
Extension methods can be called on objects that are null
.
See for example http://bradwilson.typepad.com/blog/2008/01/c-30-extension.html
Think of extension methods not as instance methods, but static methods that take the object (Result
in your case) as a first parameter.
Upvotes: 6