Visitar URL original
Should().BeEquivalentTo() throws "Sequence contains more than one matching element" when comparing classes that have a field that uses the "new" keyword to hide a field with the same name. · Issue #1982 · fluentassertions/fluentassertions · GitHub
Skip to content

Should().BeEquivalentTo() throws "Sequence contains more than one matching element" when comparing classes that have a field that uses the "new" keyword to hide a field with the same name. #1982

Closed

Description

@ERGeorgiev

I have class A that inherits class ABase. ABase contains field Id of type string. A has its own Id string field declared as new to hide the Id member coming from ABase.

Scenario:
Calling A.Should().BeEquivalentTo(A)

Expected:
The two fields are compared correctly for equivalency and the proper result is returned.

Actual:
Throws "Sequence contains more than one matching element", thrown on line 144 (return list. SingleOrDefault()) in method TypeExtensions.FindProperty() in my decompiled code.

Note:
Does not happen if you compare the same class instance to itself.

Activity

  1. dennisdoomen commented on Sep 5, 2022

    @dennisdoomen
    Member

    Although the comparison should never throw that exception (and is a bug), there's every only going to be a single field, depending on what type the instance is. If it's A, then it will compare the field Id that is marked as new. If the instance points to ABase, it'll find the base-property Id.

  2. self-assigned this
    on Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions