Skip to content

Commit

Permalink
Verify that failure message includes options
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed May 27, 2022
1 parent 55c79b3 commit b1936ab
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/CyclicReferencesSpecs.cs
Expand Up @@ -158,6 +158,22 @@ public void
act.Should().NotThrow();
}

[Fact]
public void Allowing_infinite_recursion_is_described_in_the_failure_message()
{
// Arrange
var recursiveClass1 = new ClassWithFiniteRecursiveProperty(1);
var recursiveClass2 = new ClassWithFiniteRecursiveProperty(2);

// Act
Action act = () => recursiveClass1.Should().BeEquivalentTo(recursiveClass2,
options => options.AllowingInfiniteRecursion());

// Assert
act.Should().Throw<XunitException>()
.WithMessage("*Recurse indefinitely*");
}

[Fact]
public void When_injecting_a_null_config_to_BeEquivalentTo_it_should_throw()
{
Expand Down
48 changes: 48 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/SelectionRulesSpecs.cs
Expand Up @@ -51,6 +51,54 @@ public void When_specific_properties_have_been_specified_it_should_ignore_the_ot
act.Should().NotThrow();
}

[Fact]
public void An_included_member_is_described_in_the_failure_message()
{
// Arrange
var subject = new
{
Name = "John"
};

var customer = new
{
Name = "Jack"
};

// Act
Action act = () => subject.Should().BeEquivalentTo(customer, options => options
.Including(d => d.Name));

// Assert
act.Should().Throw<XunitException>()
.WithMessage("*Include*Name*");
}

[Fact]
public void An_excluded_member_is_described_in_the_failure_message()
{
// Arrange
var subject = new
{
Name = "John",
Age = 13
};

var customer = new
{
Name = "Jack",
Age = 37
};

// Act
Action act = () => subject.Should().BeEquivalentTo(customer, options => options
.Excluding(d => d.Age));

// Assert
act.Should().Throw<XunitException>()
.WithMessage("*Exclude*Age*");
}

[Fact]
public void When_a_predicate_for_properties_to_include_has_been_specified_it_should_ignore_the_other_properties()
{
Expand Down

0 comments on commit b1936ab

Please sign in to comment.