-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
When comparing an ImmutableArray<T> against its default value using Should().BeEquivalentTo(...) an exception is thrown by the attempt to examine the array as a collection.
Complete minimal example reproducing the issue
The following shows how to produce the error:
default(ImmutableArray<string>).Should().BeEquivalentTo(default(ImmutableArray<string>));Comparing empty arrays does not cause the issue:
ImmutableArray<string>.Empty.Should().BeEquivalentTo(ImmutableArray<string>.Empty);Expected behavior:
I expect the comparison to succeed without an exception. In the case that a non-default array is compared against a default array, I expect an exception to be thrown highlighting the difference between expected and actual values.
Actual behavior:
The following exception is thrown:
Message:
System.InvalidOperationException : This operation cannot be performed on a default instance of ImmutableArray<T>. Consider initializing the array, or checking the ImmutableArray<T>.IsDefault property.
Stack Trace:
ImmutableArray`1.ThrowInvalidOperationIfNotInitialized()
ICollection<T>.get_Count()
EnumerableHelpers.ToArray[T](IEnumerable`1 source)
GenericEnumerableEquivalencyStep.HandleImpl[T](EnumerableEquivalencyValidator validator, Object[] subject, IEnumerable`1 expectation)
--- End of stack trace from previous location ---
GenericEnumerableEquivalencyStep.Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
EquivalencyValidator.RunStepsUntilEquivalencyIsProven(Comparands comparands, IEquivalencyValidationContext context)
EquivalencyValidator.RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context)
EquivalencyValidator.AssertEquality(Comparands comparands, EquivalencyValidationContext context)
StringCollectionAssertions`2.BeEquivalentTo(IEnumerable`1 expectation, Func`2 config, String because, Object[] becauseArgs)
StringCollectionAssertions`2.BeEquivalentTo(IEnumerable`1 expectation, String because, Object[] becauseArgs)
Versions
Fluent Assertions version: 6.0.0
.NET Target version: net5.0