Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change HaveCount assertion message order to state number before dumpi… #1760

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Expand Up @@ -1230,8 +1230,8 @@ public AndConstraint<TAssertions> HaveCount(int expected, string because = "", p
.ForCondition(actualCount == expected)
.BecauseOf(because, becauseArgs)
.FailWith(
"Expected {context:collection} {0} to contain {1} item(s){reason}, but found {2}.",
Subject, expected, actualCount);
"Expected {context:collection} to contain {0} item(s){reason}, but found {1}: {2}.",
expected, actualCount, Subject);
}

return new AndConstraint<TAssertions>((TAssertions)this);
Expand Down Expand Up @@ -1269,8 +1269,8 @@ public AndConstraint<TAssertions> HaveCount(int expected, string because = "", p
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:collection} {0} to have a count {1}{reason}, but count is {2}.",
Subject, countPredicate.Body, actualCount);
.FailWith("Expected {context:collection} to have a count {0}{reason}, but count is {1}: {2}.",
countPredicate.Body, actualCount, Subject);
}
}

Expand Down Expand Up @@ -1299,7 +1299,7 @@ public AndConstraint<TAssertions> HaveCountGreaterThanOrEqualTo(int expected, st
.Then
.Given(subject => subject.Count())
.ForCondition(actualCount => actualCount >= expected)
.FailWith("but found {0}.", actualCount => actualCount)
.FailWith("but found {0}: {1}.", actualCount => actualCount, actualCount => Subject)
iliashkolyar marked this conversation as resolved.
Show resolved Hide resolved
.Then
.ClearExpectation();

Expand Down Expand Up @@ -1331,7 +1331,7 @@ public AndConstraint<TAssertions> HaveCountGreaterThan(int expected, string beca
.Then
.Given(subject => subject.Count())
.ForCondition(actualCount => actualCount > expected)
.FailWith("but found {0}.", actualCount => actualCount)
.FailWith("but found {0}: {1}.", actualCount => actualCount, actualCount => Subject)
.Then
.ClearExpectation();

Expand Down Expand Up @@ -1360,7 +1360,7 @@ public AndConstraint<TAssertions> HaveCountLessThanOrEqualTo(int expected, strin
.Then
.Given(subject => subject.Count())
.ForCondition(actualCount => actualCount <= expected)
.FailWith("but found {0}.", actualCount => actualCount)
.FailWith("but found {0}: {1}.", actualCount => actualCount, actualCount => Subject)
.Then
.ClearExpectation();

Expand Down Expand Up @@ -1392,7 +1392,7 @@ public AndConstraint<TAssertions> HaveCountLessThan(int expected, string because
.Then
.Given(subject => subject.Count())
.ForCondition(actualCount => actualCount < expected)
.FailWith("but found {0}.", actualCount => actualCount)
.FailWith("but found {0}: {1}.", actualCount => actualCount, actualCount => Subject)
.Then
.ClearExpectation();

Expand Down
Expand Up @@ -46,7 +46,7 @@ public void When_collection_has_a_count_that_is_different_from_the_number_of_ite

// Assert
action.Should().Throw<XunitException>()
.WithMessage("Expected collection*1*2*3* to contain 4 item(s) because we want to test the failure message, but found 3.");
.WithMessage("Expected collection to contain 4 item(s) because we want to test the failure message, but found 3: {1, 2, 3}.");
}

[Fact]
Expand All @@ -70,7 +70,7 @@ public void When_collection_has_a_count_that_not_matches_the_predicate_it_should

// Assert
act.Should().Throw<XunitException>().WithMessage(
"Expected collection {1, 2, 3} to have a count (c >= 4) because a minimum of 4 is required, but count is 3.");
"Expected collection to have a count (c >= 4) because a minimum of 4 is required, but count is 3: {1, 2, 3}.");
}

[Fact]
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void When_collection_has_a_count_greater_than_the_number_of_items_it_shou

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*more than*3*because we want to test the failure message*3*");
.WithMessage("Expected collection to contain more than 3 item(s) because we want to test the failure message, but found 3: {1, 2, 3}.");
}

[Fact]
Expand Down
Expand Up @@ -46,7 +46,7 @@ public void When_collection_has_a_count_greater_than_or_equal_to_the_number_of_i

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*at least*4*because we want to test the failure message*3*");
.WithMessage("Expected collection to contain at least 4 item(s) because we want to test the failure message, but found 3: {1, 2, 3}.");
}

[Fact]
Expand Down
Expand Up @@ -46,7 +46,7 @@ public void When_collection_has_a_count_less_than_the_number_of_items_it_should_

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*fewer than*3*because we want to test the failure message*3*");
.WithMessage("Expected collection to contain fewer than 3 item(s) because we want to test the failure message, but found 3: {1, 2, 3}.");
}

[Fact]
Expand Down
Expand Up @@ -46,7 +46,7 @@ public void When_collection_has_a_count_less_than_or_equal_to_the_number_of_item

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*at most*2*because we want to test the failure message*3*");
.WithMessage("Expected collection to contain at most 2 item(s) because we want to test the failure message, but found 3: {1, 2, 3}.");
}

[Fact]
Expand Down
Expand Up @@ -1075,7 +1075,7 @@ public void
// Assert
action.Should().Throw<XunitException>()
.WithMessage(
"Expected collection {\"one\", \"two\", \"three\"} to contain 4 item(s) because we want to test the failure message, but found 3.");
"Expected collection to contain 4 item(s) because we want to test the failure message, but found 3: {\"one\", \"two\", \"three\"}.");
}

[Fact]
Expand All @@ -1089,7 +1089,7 @@ public void When_collection_has_a_count_that_not_matches_the_predicate_it_should

// Assert
act.Should().Throw<XunitException>().WithMessage(
"Expected collection {\"one\", \"two\", \"three\"} to have a count (c >= 4) because a minimum of 4 is required, but count is 3.");
"Expected collection to have a count (c >= 4) because a minimum of 4 is required, but count is 3: {\"one\", \"two\", \"three\"}.");
}

[Fact]
Expand Down
Expand Up @@ -172,7 +172,7 @@ public void

// Assert
action.Should().Throw<XunitException>()
.WithMessage("Expected dictionary {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"} to contain 4 item(s) because we want to test the failure message, but found 3.");
.WithMessage("Expected dictionary to contain 4 item(s) because we want to test the failure message, but found 3: {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"}.");
}

[Fact]
Expand Down Expand Up @@ -206,7 +206,7 @@ public void When_dictionary_has_a_count_that_not_matches_the_predicate_it_should

// Assert
act.Should().Throw<XunitException>().WithMessage(
"Expected dictionary {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"} to have a count (c >= 4) because a minimum of 4 is required, but count is 3.");
"Expected dictionary to have a count (c >= 4) because a minimum of 4 is required, but count is 3: {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"}.");
}

[Fact]
Expand Down Expand Up @@ -378,7 +378,7 @@ public void When_dictionary_has_a_count_greater_than_the_number_of_items_it_shou

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*more than*3*because we want to test the failure message*3*");
.WithMessage("Expected dictionary to contain more than 3 item(s) because we want to test the failure message, but found 3: {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"}.");
}

[Fact]
Expand Down Expand Up @@ -447,7 +447,7 @@ public void When_dictionary_has_a_count_greater_than_or_equal_to_the_number_of_i

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*at least*4*because we want to test the failure message*3*");
.WithMessage("Expected dictionary to contain at least 4 item(s) because we want to test the failure message, but found 3: {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"}.");
}

[Fact]
Expand Down Expand Up @@ -516,7 +516,7 @@ public void When_dictionary_has_a_count_less_than_the_number_of_items_it_should_

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*fewer than*3*because we want to test the failure message*3*");
.WithMessage("Expected dictionary to contain fewer than 3 item(s) because we want to test the failure message, but found 3: {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"}.");
}

[Fact]
Expand Down Expand Up @@ -585,7 +585,7 @@ public void When_dictionary_has_a_count_less_than_or_equal_to_the_number_of_item

// Assert
action.Should().Throw<XunitException>()
.WithMessage("*at most*2*because we want to test the failure message*3*");
.WithMessage("Expected dictionary to contain at most 2 item(s) because we want to test the failure message, but found 3: {[1] = \"One\", [2] = \"Two\", [3] = \"Three\"}.");
}

[Fact]
Expand Down
2 changes: 2 additions & 0 deletions docs/_pages/releases.md
Expand Up @@ -12,8 +12,10 @@ sidebar:
### What's New
* Adding `ThatAreAsync()` and `ThatAreNotAsync()` for filtering in method assertions - [#1725](https://github.com/fluentassertions/fluentassertions/pull/1725)
* Adding `ThatAreVirtual()` and `ThatAreNotVirtual()` for filtering in method assertions - [#1744](https://github.com/fluentassertions/fluentassertions/pull/1744)
* Adding collection content to assertion messages for `HaveCountGreaterThan()`, `HaveCountGreaterThanOrEqualTo()`, `HaveCountLessThan()` and `HaveCountLessThanOrEqualTo()` - [#1760](https://github.com/fluentassertions/fluentassertions/pull/1760)
### Fixes
* Prevent multiple enumeration of `IEnumerable`s in parameter-less `ContainSingle()` - [#1753](https://github.com/fluentassertions/fluentassertions/pull/1753)
* Change `HaveCount()` assertion message order to state expected and actual collection count before dumping its content` - [#1760](https://github.com/fluentassertions/fluentassertions/pull/1760)

## 6.2.0

Expand Down