Skip to content

GenericCollectionAssertions.BeEquivalentTo failed on sub class without properties after upgrade to 6.0-beta1 #1604

@lg2de

Description

@lg2de

Description

I've tried to update to FA 6.0 beta1 (from alpha2) in our major project.
I hit a bug on GenericCollectionAssertions.BeEquivalentTo when using on a class which sub class does not have a property.

Complete minimal example reproducing the issue

namespace FA6
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            var sut = new List<BaseClass> {new BaseClass()};

            sut.Should().BeEquivalentTo(new[] {new BaseClass()});
        }
    }

    public class BaseClass
    {
        public string Name { get; set; }
        public ClassWithoutProperty ClassWithoutProperty { get; } = new ClassWithoutProperty();
    }

    public class ClassWithoutProperty
    {
        public void Method()
        {
        }
    }
}

Expected behavior:

Test succeed.

Actual behavior:

Test failed:

System.InvalidOperationException
No members were found for comparison. Please specify some members to include in the comparison or choose a more meaningful assertion.
   at FluentAssertions.Equivalency.Steps.GenericEnumerableEquivalencyStep.Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
   at FluentAssertions.Equivalency.EquivalencyValidator.RunStepsUntilEquivalencyIsProven(Comparands comparands, IEquivalencyValidationContext context)
   at FluentAssertions.Equivalency.EquivalencyValidator.RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context)
   at FluentAssertions.Equivalency.EquivalencyValidator.AssertEquality(Comparands comparands, EquivalencyValidationContext context)
   at FluentAssertions.Collections.GenericCollectionAssertions`3.BeEquivalentTo[TExpectation](IEnumerable`1 expectation, Func`2 config, String because, Object[] becauseArgs)
   at FluentAssertions.Collections.GenericCollectionAssertions`3.BeEquivalentTo[TExpectation](IEnumerable`1 expectation, String because, Object[] becauseArgs)
   at FA6.UnitTest1.Test1() in ***\UnitTest1.cs:line 14

Versions

Verified with 6.0-beta0001 release and development version from release-6,0 branch.

Additional Information

I guess the problem is related to the implementation of FluentAssertions.Equivalency.Node.IsRoot but I'm not able to understand the logic to fix it. The step handler is checking the property ClassWithoutProperty while IsRoot returns true even it should not (I guess).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions