Skip to content

Commit

Permalink
Add missing tests for Guard
Browse files Browse the repository at this point in the history
  • Loading branch information
ITaluone committed Apr 19, 2022
1 parent bafed48 commit e86f05a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
41 changes: 39 additions & 2 deletions Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs
Expand Up @@ -1235,6 +1235,44 @@ public void When_asserting_document_has_two_child_elements_but_it_does_have_thre
"Expected document to have 2 child element(s) \"child\", but found 3.");
}

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

// Act
Action act = () => document.Should().HaveElement(null, Exactly.Twice());

// Assert
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot assert the document has an element if the expected name is <null>.*");
}

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

// Act
Action act = () => document.Should().HaveElement((XName)null, Exactly.Twice());

// Assert
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot assert the document has an element count if the element name is <null>.*");
}

[Fact]
public void Chaining_which_after_asserting_and_the_document_has_more_than_two_child_elements_it_fails()
{
Expand All @@ -1251,8 +1289,7 @@ public void Chaining_which_after_asserting_and_the_document_has_more_than_two_ch
.Which.Should().NotBeNull();

// Assert
act.Should().Throw<XunitException>().WithMessage(
"More than one object found. FluentAssertions cannot determine which object is meant*");
act.Should().NotThrow<XunitException>();
}

[Fact]
Expand Down
42 changes: 39 additions & 3 deletions Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs
Expand Up @@ -1286,7 +1286,26 @@ public void Element_has_two_child_elements_and_three_expected_it_fails()
}

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

// Act
Action act = () => element.Should().HaveElement((string)null, Exactly.Twice());

// Assert
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot assert the element has an element if the expected name is <null>.*");
}

[Fact]
public void Element_is_valid_and_expected_null_with_x_name_overload_it_fails()
{
// Arrange
var element = XElement.Parse(
Expand All @@ -1296,13 +1315,30 @@ public void Chaining_which_after_asserting_and_the_element_has_more_than_two_chi
<child />
</parent>");

// Act
Action act = () => element.Should().HaveElement((XName)null, Exactly.Twice());

// Assert
act.Should().Throw<ArgumentNullException>().WithMessage(
"Cannot assert the element has an element count if the element name is <null>.*");
}

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

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

// Assert
act.Should().Throw<XunitException>().WithMessage(
"More than one object found. FluentAssertions cannot determine which object is meant*");
act.Should().NotThrow();
}

[Fact]
Expand Down

0 comments on commit e86f05a

Please sign in to comment.