Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShouldBeEquivalentTo with Includes does not correctly compare Enums #462

Closed
brentatkins opened this issue Aug 17, 2016 · 3 comments
Closed
Assignees
Labels

Comments

@brentatkins
Copy link

brentatkins commented Aug 17, 2016

When using Including to explicitly define which member to compare, equality operations on enums don't work as expected. It only seems to compare enum lengths, but not the items within the collection.

public class CustomType
{
    public string Name { get; set; }
}

public class ClassA
{
    public List<CustomType> ListOfCustomTypes { get; set; }
}

[Test]
public void FluentAssertionsEnumIncludes()
{
    var list1 = new List<CustomType>
    {
        new CustomType {Name = "A"}, new CustomType {Name = "B"}
    };
    var list2 = new List<CustomType>
    {
        new CustomType {Name = "C"}, new CustomType {Name = "D"}
    };

    var objectA = new ClassA { ListOfCustomTypes = list1 };
    var objectB = new ClassA { ListOfCustomTypes = list2 };

    //incorrectly passes when using Includes
    objectA.ShouldBeEquivalentTo(objectB, options => options.Including(x => x.ListOfCustomTypes));

    //fails without includes
    objectA.ShouldBeEquivalentTo(objectB);
}
@dennisdoomen
Copy link
Member

dennisdoomen commented Aug 17, 2016

I managed to reproduce it. Thanks for reporting it.

@dennisdoomen
Copy link
Member

Found the cause. Somehow FA is trying to apply the .Including(x => x.ListOfCustomTypes) predicate on the CustomType as well. This obviously fails.

@brentatkins
Copy link
Author

Great! I had a go at fixing it myself, but I struggled to find my way around the codebase. Thanks for looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants