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 29, 2022
1 parent 370c674 commit a741e66
Show file tree
Hide file tree
Showing 2 changed files with 112 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
96 changes: 96 additions & 0 deletions Tests/FluentAssertions.Equivalency.Specs/SelectionRulesSpecs.cs
Expand Up @@ -51,6 +51,102 @@ public void When_specific_properties_have_been_specified_it_should_ignore_the_ot
act.Should().NotThrow();
}

[Fact]
public void A_member_included_by_path_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 A_member_included_by_predicate_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(ctx => ctx.Path == "Name"));

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

[Fact]
public void A_member_excluded_by_path_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 A_member_excluded_by_predicate_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(ctx => ctx.Path == "Age"));

// Assert
act.Should().Throw<XunitException>()
.WithMessage("*Exclude member when*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 a741e66

Please sign in to comment.