From c04d669d91429e5b49bddb9a31d948e96ceb6b98 Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger | alu-one Date: Tue, 19 Apr 2022 09:22:56 +0200 Subject: [PATCH] Re-phrase failure message to include occurrence mode --- Src/FluentAssertions/Xml/XDocumentAssertions.cs | 7 +++++-- Src/FluentAssertions/Xml/XElementAssertions.cs | 7 +++++-- .../FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs | 4 ++-- Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs | 5 +++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Src/FluentAssertions/Xml/XDocumentAssertions.cs b/Src/FluentAssertions/Xml/XDocumentAssertions.cs index 21d0c6e7f9..56ae31a067 100644 --- a/Src/FluentAssertions/Xml/XDocumentAssertions.cs +++ b/Src/FluentAssertions/Xml/XDocumentAssertions.cs @@ -314,8 +314,11 @@ public AndConstraint 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); } } diff --git a/Src/FluentAssertions/Xml/XElementAssertions.cs b/Src/FluentAssertions/Xml/XElementAssertions.cs index dc192b213f..c8a7061233 100644 --- a/Src/FluentAssertions/Xml/XElementAssertions.cs +++ b/Src/FluentAssertions/Xml/XElementAssertions.cs @@ -332,8 +332,11 @@ public AndConstraint 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>(this, xElements); diff --git a/Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs index 029d6a5391..2de6972558 100644 --- a/Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Xml/XDocumentAssertionSpecs.cs @@ -1232,7 +1232,7 @@ public void When_asserting_document_has_two_child_elements_but_it_does_have_thre // Assert act.Should().Throw().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] @@ -1247,7 +1247,7 @@ public void Document_is_valid_and_expected_null_with_string_overload_it_fails() "); // Act - Action act = () => document.Should().HaveElement(null, Exactly.Twice()); + Action act = () => document.Should().HaveElement((string)null, Exactly.Twice()); // Assert act.Should().Throw().WithMessage( diff --git a/Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs index 70fb3899da..17fe547f32 100644 --- a/Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Xml/XElementAssertionSpecs.cs @@ -1282,7 +1282,7 @@ public void Element_has_two_child_elements_and_three_expected_it_fails() // Assert act.Should().Throw().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] @@ -1330,7 +1330,8 @@ public void Chaining_which_after_asserting_and_the_element_has_more_than_two_chi var element = XElement.Parse( @" - + + "); // Act