diff --git a/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs b/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs index 1d51f9a79..06e98be08 100644 --- a/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs +++ b/Source/aweXpect.Core/Options/CollectionMatchOptions.SameOrderCollectionMatcher.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text.RegularExpressions; using aweXpect.Core; using aweXpect.Core.Helpers; @@ -60,7 +59,14 @@ public bool Verify(string it, T value, IOptionsEquality options, int maximum _index++; error = null; - return _additionalItems.Count + _incorrectItems.Count + _missingItems.Count > 2 * maximumNumber; + int errorThreshold = 2 * maximumNumber; + int errorCount = _incorrectItems.Count + _missingItems.Count; + if (!_equivalenceRelations.HasFlag(EquivalenceRelations.Contains)) + { + errorCount += _additionalItems.Count; + } + + return errorCount > errorThreshold; } #pragma warning disable S3776 // https://rules.sonarsource.com/csharp/RSPEC-3776 diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs index 2c758a838..a3df5bb9f 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionEnumerableTests.cs @@ -16,7 +16,7 @@ public sealed class EnumerableInSameOrderTests public async Task CompletelyDifferentCollections_ShouldFail() { IEnumerable subject = Enumerable.Range(1, 11); - IEnumerable expected = Enumerable.Range(100, 11); + IEnumerable expected = Enumerable.Range(100, 21); async Task Act() => await That(subject).Contains(expected); @@ -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, @@ -184,7 +184,7 @@ contained item "e" at index 4 instead of "y" and "x", "y", "z" - + Collection: [ "a", @@ -220,7 +220,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order, but it lacked all 6 expected items - + Collection: [ "b", @@ -401,6 +401,24 @@ async Task Act() await That(Act).DoesNotThrow(); } + [Fact(Skip = "TODO: Enable after updating aweXpect.Core")] + public async Task WithManyAdditionalItems_ShouldSucceed() + { + List values = [42, 5, 18, 23,]; + List results = Enumerable.Range(1, 50).SelectMany(_ => values).ToList(); + + await That(results).Contains(values); + } + + [Fact(Skip = "TODO: Enable after updating aweXpect.Core")] + public async Task WithManyAdditionalItemsAtTheBeginning_ShouldSucceed() + { + List values = [42, 5, 18, 23,]; + List results = [..Enumerable.Range(100, 50), ..values, 101, 102, 103,]; + + await That(results).Contains(values); + } + [Fact] public async Task WithMissingItem_ShouldFail() { @@ -545,7 +563,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order ignoring duplicates, but it lacked all 3 unique expected items - + Collection: [] @@ -572,7 +590,7 @@ await That(Act).Throws() Expected that subject contains collection expected in order ignoring duplicates, but it lacked all 2 unique expected items - + Collection: [] @@ -599,7 +617,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, @@ -650,7 +668,7 @@ contained item "e" at index 4 instead of "y" and "x", "y", "z" - + Collection: [ "a", @@ -686,7 +704,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", @@ -967,7 +985,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order, but it lacked all 3 expected items - + Collection: [] @@ -994,7 +1012,7 @@ await That(Act).Throws() Expected that subject contains collection expected in any order, but it lacked all 10 expected items - + Collection: [ 1, @@ -1381,7 +1399,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: [] @@ -1410,7 +1428,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: [] @@ -1437,7 +1455,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, @@ -1726,7 +1744,7 @@ public sealed class EnumerableProperlyInSameOrderTests public async Task CompletelyDifferentCollections_ShouldFail() { IEnumerable subject = Enumerable.Range(1, 11); - IEnumerable expected = Enumerable.Range(100, 11); + IEnumerable expected = Enumerable.Range(100, 21); async Task Act() => await That(subject).Contains(expected).Properly(); @@ -1785,7 +1803,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 expected items - + Collection: [] @@ -1812,7 +1830,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, @@ -1864,7 +1882,7 @@ did not contain any additional items and "x", "y", "z" - + Collection: [ "a", @@ -1902,7 +1920,7 @@ Expected that subject but it did not contain any additional items and lacked all 6 expected items - + Collection: [ "b", @@ -2256,7 +2274,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 unique expected items - + Collection: [] @@ -2285,7 +2303,7 @@ Expected that subject but it did not contain any additional items and lacked all 2 unique expected items - + Collection: [] @@ -2312,7 +2330,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, @@ -2363,7 +2381,7 @@ contained item "e" at index 4 instead of "y" and "x", "y", "z" - + Collection: [ "a", @@ -2401,7 +2419,7 @@ Expected that subject but it did not contain any additional items and lacked all 5 unique expected items - + Collection: [ "b", @@ -2808,7 +2826,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 expected items - + Collection: [] @@ -2835,7 +2853,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, @@ -3272,7 +3290,7 @@ Expected that subject but it did not contain any additional items and lacked all 3 unique expected items - + Collection: [] @@ -3303,7 +3321,7 @@ Expected that subject but it did not contain any additional items and lacked all 2 unique expected items - + Collection: [] @@ -3330,7 +3348,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,