diff --git a/Pipeline/Build.cs b/Pipeline/Build.cs index a07a0cc08..25356ef59 100644 --- a/Pipeline/Build.cs +++ b/Pipeline/Build.cs @@ -19,7 +19,7 @@ partial class Build : NukeBuild /// /// Afterward, you can update the package reference in `Directory.Packages.props` and reset this flag. /// - readonly BuildScope BuildScope = BuildScope.Default; + readonly BuildScope BuildScope = BuildScope.CoreOnly; [Parameter("Github Token")] readonly string GithubToken; diff --git a/Source/aweXpect.Core/Options/CollectionMatchOptions.cs b/Source/aweXpect.Core/Options/CollectionMatchOptions.cs index 1d12c1c05..9477dfe4d 100644 --- a/Source/aweXpect.Core/Options/CollectionMatchOptions.cs +++ b/Source/aweXpect.Core/Options/CollectionMatchOptions.cs @@ -184,6 +184,11 @@ private static IEnumerable IncorrectItemsError(Dictionary MissingItemsError(int total, List missingItems, EquivalenceRelations equivalenceRelation, bool ignoringDuplicates) { + if (total == 0) + { + yield break; + } + bool hasMissingItems = missingItems.Any(); if (total == missingItems.Count) { diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs index 545e9b755..f71fd1536 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs @@ -73,7 +73,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order, but it lacked all 3 expected items - + Collection: [] @@ -100,7 +100,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order, but it lacked all 10 expected items - + Collection: [ 1, @@ -131,6 +131,18 @@ but it lacked all 10 expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected); + + await That(Act).DoesNotThrow(); + } + [Fact] public async Task WhenExpectedIsNull_ShouldFail() { @@ -184,7 +196,7 @@ contained item "e" at index 4 instead of "y" and "x", "y", "z" - + Collection: [ "a", @@ -220,7 +232,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order, but it lacked all 6 expected items - + Collection: [ "b", @@ -544,7 +556,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order ignoring duplicates, but it lacked all 3 unique expected items - + Collection: [] @@ -571,7 +583,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order ignoring duplicates, but it lacked all 2 unique expected items - + Collection: [] @@ -598,7 +610,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order ignoring duplicates, but it lacked all 10 unique expected items - + Collection: [ 1, @@ -629,6 +641,35 @@ but it lacked all 10 unique expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).Contains(expected!).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + contains collection expected in order ignoring duplicates, + but it cannot compare to + """); + } + [Fact] public async Task WithAdditionalAndMissingItems_ShouldFail() { @@ -649,7 +690,7 @@ contained item "e" at index 4 instead of "y" and "x", "y", "z" - + Collection: [ "a", @@ -685,7 +726,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order ignoring duplicates, but it lacked all 5 unique expected items - + Collection: [ "b", @@ -966,7 +1007,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order, but it lacked all 3 expected items - + Collection: [] @@ -993,7 +1034,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order, but it lacked all 10 expected items - + Collection: [ 1, @@ -1024,6 +1065,35 @@ but it lacked all 10 expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).Contains(expected!).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + contains collection expected in any order, + but it cannot compare to + """); + } + [Fact] public async Task WithAdditionalAndMissingItems_ShouldFail() { @@ -1379,7 +1449,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order ignoring duplicates, but it lacked all 3 unique expected items - + Collection: [] @@ -1408,7 +1478,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order ignoring duplicates, but it lacked all 2 unique expected items - + Collection: [] @@ -1435,7 +1505,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order ignoring duplicates, but it lacked all 10 unique expected items - + Collection: [ 1, @@ -1466,6 +1536,35 @@ but it lacked all 10 unique expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).Contains(expected!).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + contains collection expected in any order ignoring duplicates, + but it cannot compare to + """); + } + [Fact] public async Task WithAdditionalAndMissingItems_ShouldFail() { @@ -1783,7 +1882,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 expected items - + Collection: [] @@ -1810,7 +1909,7 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order, but it lacked all 10 expected items - + Collection: [ 1, @@ -1862,7 +1961,7 @@ did not contain any additional items and "x", "y", "z" - + Collection: [ "a", @@ -1900,7 +1999,7 @@ Expected that subject but it did not contain any additional items and lacked all 6 expected items - + Collection: [ "b", @@ -2253,7 +2352,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 unique expected items - + Collection: [] @@ -2282,7 +2381,7 @@ Expected that subject but it did not contain any additional items and lacked all 2 unique expected items - + Collection: [] @@ -2309,7 +2408,7 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, but it lacked all 10 unique expected items - + Collection: [ 1, @@ -2360,7 +2459,7 @@ contained item "e" at index 4 instead of "y" and "x", "y", "z" - + Collection: [ "a", @@ -2398,7 +2497,7 @@ Expected that subject but it did not contain any additional items and lacked all 5 unique expected items - + Collection: [ "b", @@ -2805,7 +2904,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 expected items - + Collection: [] @@ -2832,7 +2931,7 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in any order, but it lacked all 10 expected items - + Collection: [ 1, @@ -3268,7 +3367,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 unique expected items - + Collection: [] @@ -3299,7 +3398,7 @@ Expected that subject but it did not contain any additional items and lacked all 2 unique expected items - + Collection: [] @@ -3326,7 +3425,7 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in any order ignoring duplicates, but it lacked all 10 unique expected items - + Collection: [ 1, diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs index 98274e059..e2cf5c67d 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs @@ -130,7 +130,6 @@ but it lacked all 10 expected items """); } - [Fact] public async Task WhenExpectedContainsDuplicateButMissingItems_ShouldFail() { @@ -155,6 +154,18 @@ contained item 12 at index 4 instead of 2 """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected); + + await That(Act).DoesNotThrow(); + } + [Fact] public async Task WhenExpectedIsNull_ShouldFail() { @@ -683,6 +694,35 @@ but it lacked all 10 unique expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldFail() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).Contains(expected!).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + contains collection expected in order ignoring duplicates, + but it cannot compare to + """); + } + [Fact] public async Task WithAdditionalAndMissingItems_ShouldFail() { @@ -1108,6 +1148,35 @@ but it lacked all 10 expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldFail() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).Contains(expected!).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + contains collection expected in any order, + but it cannot compare to + """); + } + [Fact] public async Task WithAdditionalAndMissingItems_ShouldFail() { @@ -1551,6 +1620,35 @@ but it lacked all 10 unique expected items """); } + [Fact] + public async Task WhenExpectedIsEmpty_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = []; + + async Task Act() + => await That(subject).Contains(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldFail() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).Contains(expected!).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + contains collection expected in any order ignoring duplicates, + but it cannot compare to + """); + } + [Fact] public async Task WithAdditionalAndMissingItems_ShouldFail() { @@ -4135,14 +4233,14 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order ignoring interspersed items, but it did not contain any additional items - + Collection: [ "a", "b", "c" ] - + Expected: [ "a", @@ -4162,7 +4260,8 @@ public async Task WithInterspersedItems_ShouldSucceed() string[] expected = ["a", "c",]; async Task Act() - => await That(subject).Contains(expected).Properly().IgnoringDuplicates().IgnoringInterspersedItems(); + => await That(subject).Contains(expected).Properly().IgnoringDuplicates() + .IgnoringInterspersedItems(); await That(Act).DoesNotThrow(); } @@ -4174,7 +4273,8 @@ public async Task WithInterspersedItemsInDifferentOrder_ShouldFail() string[] expected = ["b", "a",]; async Task Act() - => await That(subject).Contains(expected).Properly().IgnoringInterspersedItems().IgnoringDuplicates(); + => await That(subject).Contains(expected).Properly().IgnoringInterspersedItems() + .IgnoringDuplicates(); await That(Act).Throws() .WithMessage(""" @@ -4204,21 +4304,22 @@ public async Task WithSameCollection_ShouldFail() string[] expected = ["a", "b", "c",]; async Task Act() - => await That(subject).Contains(expected).Properly().IgnoringDuplicates().IgnoringInterspersedItems(); + => await That(subject).Contains(expected).Properly().IgnoringDuplicates() + .IgnoringInterspersedItems(); await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates and interspersed items, but it did not contain any additional items - + Collection: [ "a", "b", "c" ] - + Expected: [ "a",