Skip to content

Commit

Permalink
Re-phrase failure message to include occurrence mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ITaluone committed Apr 19, 2022
1 parent e86f05a commit c04d669
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions Src/FluentAssertions/Xml/XDocumentAssertions.cs
Expand Up @@ -314,8 +314,11 @@ public AndConstraint<XDocumentAssertions> NotBeEquivalentTo(XDocument unexpected
.ForConstraint(occurrenceConstraint, actualCount)
.BecauseOf(because, becauseArgs)
.FailWith(
"Expected {context:subject} to have {0} child element(s) {1}{reason}, but found {2}.",
occurrenceConstraint.ExpectedCount, expected.ToString(), actualCount);
"Expected {context:subject} to have {0} {1} child element(s) {2}{reason}, but found {3}.",
occurrenceConstraint.Mode,
occurrenceConstraint.ExpectedCount,
expected.ToString(),
actualCount);
}
}

Expand Down
7 changes: 5 additions & 2 deletions Src/FluentAssertions/Xml/XElementAssertions.cs
Expand Up @@ -332,8 +332,11 @@ public AndConstraint<XElementAssertions> HaveValue(string expected, string becau
.ForConstraint(occurrenceConstraint, actualCount)
.BecauseOf(because, becauseArgs)
.FailWith(
"Expected {context:subject} to have {0} child element(s) {1}{reason}, but found {2}.",
occurrenceConstraint.ExpectedCount, expected.ToString(), actualCount);
"Expected {context:subject} to have {0} {1} child element(s) {2}{reason}, but found {3}.",
occurrenceConstraint.Mode,
occurrenceConstraint.ExpectedCount,
expected.ToString(),
actualCount);
}

return new AndWhichConstraint<XElementAssertions, IEnumerable<XElement>>(this, xElements);
Expand Down
4 changes: 2 additions & 2 deletions Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs
Expand Up @@ -1232,7 +1232,7 @@ public void When_asserting_document_has_two_child_elements_but_it_does_have_thre

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

[Fact]
Expand All @@ -1247,7 +1247,7 @@ public void Document_is_valid_and_expected_null_with_string_overload_it_fails()
</parent>");

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

// Assert
act.Should().Throw<ArgumentNullException>().WithMessage(
Expand Down
5 changes: 3 additions & 2 deletions Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs
Expand Up @@ -1282,7 +1282,7 @@ public void Element_has_two_child_elements_and_three_expected_it_fails()

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

[Fact]
Expand Down Expand Up @@ -1330,7 +1330,8 @@ public void Chaining_which_after_asserting_and_the_element_has_more_than_two_chi
var element = XElement.Parse(
@"<parent>
<child />
<child />
<child />
</parent>");

// Act
Expand Down

0 comments on commit c04d669

Please sign in to comment.