shouldly / shouldly

Should testing for .NET—the way assertions should be!

Home Page:https://docs.shouldly.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ShouldBeEquivalentTo ignores fields

loop-evgeny opened this issue · comments

v4.0.3. ShouldBeEquivalentTo does not appear to compare fields - it passes for two objects with different field values, like this:

    [TestFixture]
    public class SomeTests
    {
        private class MyObject
        {
            public string Field;
            public string Property { get; set; }
        }

        [Test]
        public void CompareObjects()
        {
            //new MyObject {Property = "actual"}.ShouldBeEquivalentTo(new MyObject {Property = "expected"}); // Shouldly fails - good
            new MyObject {Field = "actual"}.ShouldBeEquivalentTo(new MyObject {Field = "expected"}); // Shouldly - passes!
            new MyObject {Field = "actual"}.Should().BeEquivalentTo(new MyObject {Field = "expected"}); // FluentAssertions - fails as expected
        }
    }

I see no documentation on ShouldBeEquivalentTo on docs.shouldly.io but sounds like it's supposed to behave like the FluentAssertions equivalent?

Hi @loop-evgeny,

Thanks for raising the issue you're seeing. This feature is still in its infancy and is rather primitive at the so feedback like this is super useful.

I'm calling this a bug because I think it was missed in design to consider how we wanted this to play out, and I'm tentatively milestoning for 4.1 to minimize the amount of time in which tests might be written that could break when we roll this out.

Should be able to close this one now #790 is in 👍