1

Closed

TypeAssertions throws NullReferenceException when checking Should().Be(null)

description

FluentAssertions 1.7.1, net35 version.

Type type = GetNullType();
type.Should().Be(null);

throws NullReferenceException if type is null:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
TypeAssertions.GetFailureMessageIfTypesAreDifferent(Type actual, Type expected)
TypeAssertions.Be(Type expected, String reason, Object[] reasonArgs)
TypeAssertions.Be(Type expected)
...

A valid workaround:

Object type = GetNullType();
type.Should().Be(null); // or type.Should().BeNull();

Asides from the unexpected exception, I think TypeAssertions should provide a BeNull method also.
Closed Mar 4 at 11:24 AM by dennisdoomen
Was already fixed in 2.0.0

comments