-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ShouldContainMatchingCount'
- Loading branch information
Showing
9 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/Shouldly.Tests.Shared/ShouldContain/CollectionPredicateWithCountScenario.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using Shouldly.Tests.Strings; | ||
using Xunit; | ||
|
||
namespace Shouldly.Tests.Shared.ShouldContain | ||
{ | ||
public class CollectionPredicateWithCountScenario | ||
{ | ||
[Fact] | ||
public void CollectionWithACountOtherThanTheSpecifiedCountOfMatchingPredicatesFails() | ||
{ | ||
var collection = new[] { "a", "b", "c", "c" }; | ||
Verify.ShouldFail(() => | ||
collection.ShouldContain(x => x == "c", 5), | ||
#if net35 | ||
errorWithSource: | ||
@"collection | ||
should contain 5 element(s) satisfying the condition | ||
(x = ""c"") | ||
but does not", | ||
errorWithoutSource: | ||
@"[""a"", ""b"", ""c"", ""c""] | ||
should contain 5 element(s) satisfying the condition | ||
(x = ""c"") | ||
but does not"); | ||
#else | ||
|
||
errorWithSource: | ||
@"collection | ||
should contain 5 element(s) satisfying the condition | ||
(x == ""c"") | ||
but does not", | ||
errorWithoutSource: | ||
@"[""a"", ""b"", ""c"", ""c""] | ||
should contain 5 element(s) satisfying the condition | ||
(x == ""c"") | ||
but does not"); | ||
#endif | ||
} | ||
|
||
[Fact] | ||
public void CollectionWithACountOtherThanTheSpecifiedCountOfMatchingPredicatesFailsWithCustomMessage() | ||
{ | ||
var collection = new[] { "a", "b", "c", "c" }; | ||
Verify.ShouldFail(() => | ||
collection.ShouldContain(x => x == "c", 5, "custom message"), | ||
#if net35 | ||
errorWithSource: | ||
@"collection | ||
should contain 5 element(s) satisfying the condition | ||
(x = ""c"") | ||
but does not | ||
Additional Info: | ||
custom message", | ||
errorWithoutSource: | ||
@"[""a"", ""b"", ""c"", ""c""] | ||
should contain 5 element(s) satisfying the condition | ||
(x = ""c"") | ||
but does not | ||
Additional Info: | ||
custom message"); | ||
#else | ||
errorWithSource: | ||
@"collection | ||
should contain 5 element(s) satisfying the condition | ||
(x == ""c"") | ||
but does not | ||
Additional Info: | ||
custom message", | ||
errorWithoutSource: | ||
@"[""a"", ""b"", ""c"", ""c""] | ||
should contain 5 element(s) satisfying the condition | ||
(x == ""c"") | ||
but does not | ||
Additional Info: | ||
custom message"); | ||
#endif | ||
} | ||
|
||
[Fact] | ||
public void CollectionWithACountOtherThanTheSpecifiedCountOfMatchingPredicatesFailsWithCustomMessageFunc() | ||
{ | ||
var collection = new[] { "a", "b", "c", "c" }; | ||
Verify.ShouldFail(() => | ||
collection.ShouldContain(x => x == "c", 5, () => "custom message"), | ||
#if net35 | ||
errorWithSource: | ||
@"collection | ||
should contain 5 element(s) satisfying the condition | ||
(x = ""c"") | ||
but does not | ||
Additional Info: | ||
custom message", | ||
errorWithoutSource: | ||
@"[""a"", ""b"", ""c"", ""c""] | ||
should contain 5 element(s) satisfying the condition | ||
(x = ""c"") | ||
but does not | ||
Additional Info: | ||
custom message"); | ||
#else | ||
|
||
errorWithSource: | ||
@"collection | ||
should contain 5 element(s) satisfying the condition | ||
(x == ""c"") | ||
but does not | ||
Additional Info: | ||
custom message", | ||
errorWithoutSource: | ||
@"[""a"", ""b"", ""c"", ""c""] | ||
should contain 5 element(s) satisfying the condition | ||
(x == ""c"") | ||
but does not | ||
Additional Info: | ||
custom message"); | ||
#endif | ||
} | ||
|
||
[Fact] | ||
public void CollectionWithTheSpecifiedCountOfMatchingPredicatesSucceeds() | ||
{ | ||
new[] { "a","b","c","c"}.ShouldContain(x => x == "c", 2); // collection has exactly two items that are "c" | ||
new[] { 1, 2, 3, 4 }.ShouldContain(i => (i % 2) == 0, 2); // collection has exactly two items that are even | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters