-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
We have a bug, where a NullReferenceException is thrown if the expectation is a dictionary type and the subject is null.
For other enumerables GenericEnumerableEquivalencyStep.AssertSubjectIsCollection checks if the subject is not null.
There is no such check in GenericDictionaryEquivalencyStep and AssertIsCompatiblyTypedDictionary will throw an NRE on subject.GetType() when subject is null.
Complete minimal example reproducing the issue
[Fact]
public void When_a_dictionary_is_compared_to_null_it_should_not_throw_a_NullReferenceException()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
Dictionary<int, int> subject = null;
Dictionary<int, int> expectation = new Dictionary<int, int>();
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => subject.Should().BeEquivalentTo(expectation);
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<XunitException>();
}Expected behavior:
The test should pass, as BeEquivalenTo should throw an XunitException.
Actual behavior:
The test fails as a NullReferenceException is thrown.
Versions
Fluent Assertions 5.4.2
Thanks to @SneManden for reporting