Skip to content

Commit

Permalink
Moved the exclusion of non-browsable members in the subject from Asse…
Browse files Browse the repository at this point in the history
…rtMemberEquality to FindMatchFor in StructuralEqualityEquivalencyStep.cs.
  • Loading branch information
logiclrd committed Mar 1, 2022
1 parent 648e618 commit 307d80a
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,21 @@ public class StructuralEqualityEquivalencyStep : IEquivalencyStep
IMember matchingMember = FindMatchFor(selectedMember, context.CurrentNode, comparands.Subject, options);
if (matchingMember is not null)
{
// This excludes non-browsable members from the subject. If a member is marked non-browsable
// in the expectation, it gets excluded in GetMembersFromExpectation.
if (!options.ExcludeNonBrowsable || matchingMember.IsBrowsable)
var nestedComparands = new Comparands
{
var nestedComparands = new Comparands
{
Subject = matchingMember.GetValue(comparands.Subject),
Expectation = selectedMember.GetValue(comparands.Expectation),
CompileTimeType = selectedMember.Type
};

if (selectedMember.Name != matchingMember.Name)
{
// In case the matching process selected a different member on the subject,
// adjust the current member so that assertion failures report the proper name.
selectedMember.Name = matchingMember.Name;
}

parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(selectedMember));
Subject = matchingMember.GetValue(comparands.Subject),
Expectation = selectedMember.GetValue(comparands.Expectation),
CompileTimeType = selectedMember.Type
};

if (selectedMember.Name != matchingMember.Name)
{
// In case the matching process selected a different member on the subject,
// adjust the current member so that assertion failures report the proper name.
selectedMember.Name = matchingMember.Name;
}

parent.RecursivelyAssertEquality(nestedComparands, context.AsNestedMember(selectedMember));
}
}

Expand All @@ -87,6 +82,13 @@ public class StructuralEqualityEquivalencyStep : IEquivalencyStep
where match is not null
select match;

// This excludes non-browsable members from the subject. If a member is marked non-browsable
// in the expectation, it gets excluded in GetMembersFromExpectation.
if (config.ExcludeNonBrowsable)
{
query = query.Where(member => member.IsBrowsable);
}

return query.FirstOrDefault();
}

Expand All @@ -102,7 +104,7 @@ public class StructuralEqualityEquivalencyStep : IEquivalencyStep
}

// This excludes non-browsable members from the expectation. If a member is marked non-browsable
// in the subject, it gets excluded in AssertMemberEquality.
// in the subject, it gets excluded in FindMatchFor.
if (options.ExcludeNonBrowsable)
{
members = members.Where(member => member.IsBrowsable);
Expand Down

0 comments on commit 307d80a

Please sign in to comment.