Skip to content

Commit

Permalink
Added tests of cases where a member marked non-browsable doesn't have…
Browse files Browse the repository at this point in the history
… a corresponding member on the other side of the comparison to SelectionRulesSpecs.cs in nested class NonBrowsableOnOneButMissingFromTheOther.

Updated MustMatchByNameRule.cs to check for non-browsable members and ExcludeNonBrowsable before failing the assertion due to a missing member. This resolves failures in the newly-added tests.
  • Loading branch information
logiclrd committed Feb 27, 2022
1 parent e4a65db commit 6807f9b
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public IMember Match(IMember expectedMember, object subject, INode parent, IEqui

if (subjectMember is null)
{
Execute.Assertion.FailWith(
$"Expectation has {expectedMember.Description} that the other object does not have.");
bool ignoreMemberBecauseItIsNotBrowsable = config.ExcludeNonBrowsable && !expectedMember.IsBrowsable;

if (!ignoreMemberBecauseItIsNotBrowsable)
{
Execute.Assertion.FailWith(
$"Expectation has {expectedMember.Description} that the other object does not have.");
}
}

return subjectMember;
Expand Down
139 changes: 139 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/SelectionRulesSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,145 @@ public void When_field_is_non_browsable_only_in_expectation_excluding_non_browsa
subject.Should().BeEquivalentTo(expectation, config => config.ExcludingNonBrowsableMembers());
}

public class NonBrowsableOnOneButMissingFromTheOther
{
[Fact]
public void When_property_is_missing_from_subject_excluding_non_browsable_members_should_make_it_succeed()
{
// Arrange
var subject =
new
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
NonBrowsableField = 2,
/* NonBrowsableProperty missing */
};

var expected =
new ClassWithNonBrowsableMembers
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
NonBrowsableField = 2,
NonBrowsableProperty = 2,
};

// Act & Assert
subject.Should().BeEquivalentTo(expected, opt => opt.ExcludingNonBrowsableMembers());
}

[Fact]
public void When_field_is_missing_from_subject_excluding_non_browsable_members_should_make_it_succeed()
{
// Arrange
var subject =
new
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
/* NonBrowsableField missing */
NonBrowsableProperty = 2,
};

var expected =
new ClassWithNonBrowsableMembers
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
NonBrowsableField = 2,
NonBrowsableProperty = 2,
};

// Act & Assert
subject.Should().BeEquivalentTo(expected, opt => opt.ExcludingNonBrowsableMembers());
}

[Fact]
public void When_property_is_missing_from_expectation_excluding_non_browsable_members_should_make_it_succeed()
{
// Arrange
var subject =
new ClassWithNonBrowsableMembers
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
NonBrowsableField = 2,
NonBrowsableProperty = 2,
};

var expected =
new
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
NonBrowsableField = 2,
/* NonBrowsableProperty missing */
};

// Act & Assert
subject.Should().BeEquivalentTo(expected, opt => opt.ExcludingNonBrowsableMembers());
}

[Fact]
public void When_field_is_missing_from_expectation_excluding_non_browsable_members_should_make_it_succeed()
{
// Arrange
var subject =
new ClassWithNonBrowsableMembers
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
NonBrowsableField = 2,
NonBrowsableProperty = 2,
};

var expected =
new
{
BrowsableField = 1,
BrowsableProperty = 1,
ExplicitlyBrowsableField = 1,
ExplicitlyBrowsableProperty = 1,
AdvancedBrowsableField = 1,
AdvancedBrowsableProperty = 1,
/* NonBrowsableField missing */
NonBrowsableProperty = 2,
};

// Act & Assert
subject.Should().BeEquivalentTo(expected, opt => opt.ExcludingNonBrowsableMembers());
}
}

private class ClassWithNonBrowsableMembers
{
public int BrowsableField = -1;
Expand Down

0 comments on commit 6807f9b

Please sign in to comment.