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.SameOrderCollectionMatcher.cs b/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs index a7236658e..2f32f296c 100644 --- a/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs +++ b/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs @@ -84,7 +84,7 @@ public bool VerifyComplete(string it, IOptionsEquality options, int maximumN } List errors = new(); - errors.AddRange(IncorrectItemsError(_incorrectItems, _expectedItems, _equivalenceRelations)); + errors.AddRange(IncorrectItemsError(_incorrectItems)); if (!_equivalenceRelations.HasFlag(EquivalenceRelations.Contains)) { errors.AddRange(AdditionalItemsError(_additionalItems)); diff --git a/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderIgnoreDuplicatesCollectionMatcher.cs b/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderIgnoreDuplicatesCollectionMatcher.cs index e95a2230a..eb4c2e0b3 100644 --- a/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderIgnoreDuplicatesCollectionMatcher.cs +++ b/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderIgnoreDuplicatesCollectionMatcher.cs @@ -101,7 +101,7 @@ public bool VerifyComplete(string it, IOptionsEquality options, int maximumN } List errors = new(); - errors.AddRange(IncorrectItemsError(_incorrectItems, _expectedDistinctItems, _equivalenceRelations)); + errors.AddRange(IncorrectItemsError(_incorrectItems)); if (!_equivalenceRelations.HasFlag(EquivalenceRelations.Contains)) { errors.AddRange(AdditionalItemsError(_additionalItems)); diff --git a/Source/aweXpect.Core/Options/CollectionMatchOptions.cs b/Source/aweXpect.Core/Options/CollectionMatchOptions.cs index de6edb16b..1acddf374 100644 --- a/Source/aweXpect.Core/Options/CollectionMatchOptions.cs +++ b/Source/aweXpect.Core/Options/CollectionMatchOptions.cs @@ -152,21 +152,13 @@ private static IEnumerable AdditionalItemsError(Dictionary ad } } - private static IEnumerable IncorrectItemsError(Dictionary incorrectItems, - T[] expectedItems, - EquivalenceRelations equivalenceRelation) + private static IEnumerable IncorrectItemsError(Dictionary incorrectItems) { bool hasIncorrectItems = incorrectItems.Any(); if (hasIncorrectItems) { foreach (KeyValuePair incorrectItem in incorrectItems) { - if (equivalenceRelation.HasFlag(EquivalenceRelations.Contains) && - !expectedItems.Contains(incorrectItem.Value.Item)) - { - continue; - } - yield return $"contained item {Formatter.Format(incorrectItem.Value.Item)} at index {incorrectItem.Key} instead of {Formatter.Format(incorrectItem.Value.Expected)}"; } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs index 0387f5f20..4b9436901 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs @@ -190,11 +190,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -669,11 +672,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -1922,12 +1928,14 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order, but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and did not contain any additional items and lacked 3 of 6 expected items: "x", "y", "z" - + Collection: [ "a", @@ -2433,11 +2441,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs index ba0615b91..8b824e055 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs @@ -190,11 +190,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -670,11 +673,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -1924,12 +1930,14 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order, but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and did not contain any additional items and lacked 3 of 6 expected items: "x", "y", "z" - + Collection: [ "a", @@ -2436,11 +2444,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionImmutableTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionImmutableTests.cs index c88e82497..eecde641c 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionImmutableTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionImmutableTests.cs @@ -191,11 +191,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -671,11 +674,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -1925,12 +1931,14 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order, but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and did not contain any additional items and lacked 3 of 6 expected items: "x", "y", "z" - + Collection: [ "a", @@ -2437,11 +2445,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs index 813f99dff..0a6a09a94 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs @@ -143,6 +143,31 @@ Expected that subject """); } + + [Fact] + public async Task WhenExpectedContainsDuplicateButMissingItems_ShouldFail() + { + int[] collection = [1, 2, 1, 3, 12, 2, 2,]; + + async Task Act() + => await That(collection).Contains([1, 2, 1, 1, 2,]); + + await That(Act).Throws() + .WithMessage(""" + Expected that collection + contains collection [1, 2, 1, 1, 2,] in order, + but it + contained item 3 at index 3 instead of 1 and + contained item 12 at index 4 instead of 2 + + Collection: + [1, 2, 1, 3, 12, 2, 2] + + Expected: + [1, 2, 1, 1, 2] + """); + } + [Fact] public async Task WhenExpectedIsNull_ShouldFail() { @@ -189,11 +214,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -669,11 +697,14 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" - + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" + Collection: [ "a", @@ -1923,6 +1954,8 @@ await That(Act).Throws() Expected that subject contains collection expected and at least one additional item in order, but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and did not contain any additional items and lacked 3 of 6 expected items: "x", @@ -2435,10 +2468,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, - but it lacked 3 of 6 expected items: - "x", - "y", - "z" + but it + contained item "d" at index 3 instead of "x" and + contained item "e" at index 4 instead of "y" and + lacked 3 of 6 expected items: + "x", + "y", + "z" Collection: [