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

@ERGeorgiev

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions