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 679f0ff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Src/FluentAssertions/Xml/XDocumentAssertions.cs
Expand Up @@ -314,8 +314,10 @@ 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 {occurrenceConstraint.Mode} {{0}} child element(s) {{1}}{{reason}}, but found {{2}}.",
occurrenceConstraint.ExpectedCount,
expected.ToString(),
actualCount);
}
}

Expand Down
6 changes: 4 additions & 2 deletions Src/FluentAssertions/Xml/XElementAssertions.cs
Expand Up @@ -332,8 +332,10 @@ 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 {occurrenceConstraint.Mode} {{0}} child element(s) {{1}}{{reason}}, but found {{2}}.",
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 679f0ff

Please sign in to comment.