Skip to content

Possible problem with IgnoringCyclicReferences #192

Closed
@Lette

Description

In version 2.0.1 the following test was passing:

using FluentAssertions;
using NUnit.Framework;

namespace FluentAssertionTests
{
    [TestFixture]
    public class Tests
    {
        [Test]
        public void ShouldBeEquivalentTo_works()
        {
            var a = new Parent();
            a.Child1 = new Child(a, 1);
            a.Child2 = new Child(a);

            var b = new Parent();
            b.Child1 = new Child(b);
            b.Child2 = new Child(b);

            a.ShouldBeEquivalentTo(b, x => x
                .Excluding(y => y.Child1)
                .IgnoringCyclicReferences());
        }
    }

    public class Parent
    {
        public Child Child1 { get; set; }
        public Child Child2 { get; set; }
    }

    public class Child
    {
        public Child(Parent parent, int stuff = 0)
        {
            Parent = parent;
            Stuff = stuff;
        }

        public Parent Parent { get; set; }
        public int Stuff { get; set; }

    }
}

This test fails in 2.1.0, and it doesn't pass in the latest nuget package (3.2.1) either.

It fails with Expected property Child2.Parent.Child1.Stuff to be 0, but found 1., even though we explicitly stated that property Child1 should be excluded and that we want to ignore cyclic references.

I'm fairly sure that the back reference Child2.Parent should be considered a cyclic reference.

Is there a cycle detection problem here, or am I using FA the wrong way?

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions