Skip to content

Commit

Permalink
Fix test names that are incorrect and/or awkward to read
Browse files Browse the repository at this point in the history
  • Loading branch information
ITaluone committed Apr 19, 2022
1 parent 679f0ff commit a5085eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
27 changes: 22 additions & 5 deletions Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs
Expand Up @@ -1177,7 +1177,7 @@ public void When_asserting_document_has_two_child_elements_and_it_does_it_succee
}

[Fact]
public void Asserting_document_inside_an_assertion_scope_it_checks_the_whole_assertion_scope_before_failing()
public void Asserting_document_null_inside_an_assertion_scope_it_checks_the_whole_assertion_scope_before_failing()
{
// Arrange
XDocument document = null;
Expand All @@ -1197,7 +1197,7 @@ public void Asserting_document_inside_an_assertion_scope_it_checks_the_whole_ass
}

[Fact]
public void Asserting_document_inside_an_assertion_scope_it_checks_the_whole_assertion_scope_before_failing_()
public void Asserting_with_document_root_null_inside_an_assertion_scope_it_checks_the_whole_assertion_scope_before_failing()
{
// Arrange
XDocument document = new();
Expand Down Expand Up @@ -1274,7 +1274,7 @@ public void Document_is_valid_and_expected_null_with_x_name_overload_it_fails()
}

[Fact]
public void Chaining_which_after_asserting_and_the_document_has_more_than_two_child_elements_it_fails()
public void Chaining_after_a_successful_occurrence_check_does_continue_the_assertion()
{
// Arrange
var document = XDocument.Parse(
Expand All @@ -1284,12 +1284,29 @@ public void Chaining_which_after_asserting_and_the_document_has_more_than_two_ch
<child />
</parent>");

// Act / Assert
document.Should().HaveElement("child", AtLeast.Twice())
.Which.Should().NotBeNull();
}

[Fact]
public void Chaining_after_a_non_successful_occurrence_check_does_not_continue_the_assertion()
{
// Arrange
var document = XDocument.Parse(
@"<parent>
<child />
<child />
<child />
</parent>");

// Act
Action act = () => document.Should().HaveElement("child", AtLeast.Twice())
Action act = () => document.Should().HaveElement("child", Exactly.Once())
.Which.Should().NotBeNull();

// Assert
act.Should().NotThrow<XunitException>();
act.Should().Throw<XunitException>()
.WithMessage("Expected document to have *exactly*1 child element(s) \"child\", but found 3.");
}

[Fact]
Expand Down
23 changes: 20 additions & 3 deletions Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs
Expand Up @@ -1324,7 +1324,23 @@ public void Element_is_valid_and_expected_null_with_x_name_overload_it_fails()
}

[Fact]
public void Chaining_which_after_asserting_and_the_element_has_more_than_two_child_elements_it_fails()
public void Chaining_after_a_successful_occurrence_check_does_continue_the_assertion()
{
// Arrange
var element = XElement.Parse(
@"<parent>
<child />
<child />
<child />
</parent>");

// Act / Assert
element.Should().HaveElement("child", AtLeast.Twice())
.Which.Should().NotBeNull();
}

[Fact]
public void Chaining_after_a_non_successful_occurrence_check_does_not_continue_the_assertion()
{
// Arrange
var element = XElement.Parse(
Expand All @@ -1335,11 +1351,12 @@ public void Chaining_which_after_asserting_and_the_element_has_more_than_two_chi
</parent>");

// Act
Action act = () => element.Should().HaveElement("child", AtLeast.Twice())
Action act = () => element.Should().HaveElement("child", Exactly.Once())
.Which.Should().NotBeNull();

// Assert
act.Should().NotThrow();
act.Should().Throw<XunitException>()
.WithMessage("Expected element to have *exactly*1 child element(s) \"child\", but found 3.");
}

[Fact]
Expand Down

0 comments on commit a5085eb

Please sign in to comment.