diff --git a/Docs/pages/docs/expectations/07-collections.md b/Docs/pages/docs/expectations/07-collections.md index 5ab2c915d..848fccc67 100644 --- a/Docs/pages/docs/expectations/07-collections.md +++ b/Docs/pages/docs/expectations/07-collections.md @@ -253,6 +253,8 @@ await Expect.That(values).Contains([1, 1, 2, 2]).IgnoringDuplicates(); await Expect.That(values).Contains([3, 3, 1, 1]).InAnyOrder().IgnoringDuplicates(); ``` +*Note: You can also negate this expectation with `DoesNotContain`.* + *Note: The same expectation works also for `IAsyncEnumerable`.* To check for a proper subset, append `.Properly()` (which would fail for equal collections). @@ -270,6 +272,8 @@ await Expect.That(values).IsContainedIn([1, 1, 2, 2, 3, 3, 4, 4]).IgnoringDuplic await Expect.That(values).IsContainedIn([4, 4, 3, 3, 2, 2, 1, 1]).InAnyOrder().IgnoringDuplicates(); ``` +*Note: You can also negate this expectation with `IsNotContainedIn`.* + *Note: The same expectation works also for `IAsyncEnumerable`.* To check for a proper superset, append `.Properly()` (which would fail for equal collections). diff --git a/Source/aweXpect/That/Collections/ThatAsyncEnumerable.Contains.cs b/Source/aweXpect/That/Collections/ThatAsyncEnumerable.Contains.cs index 52697cac1..ba6a16ae2 100644 --- a/Source/aweXpect/That/Collections/ThatAsyncEnumerable.Contains.cs +++ b/Source/aweXpect/That/Collections/ThatAsyncEnumerable.Contains.cs @@ -217,6 +217,52 @@ public static CountResult, IThat quantifier); } + /// + /// Verifies that the collection does not contain the provided collection. + /// + public static ObjectCollectionContainResult, IThat?>, TItem> + DoesNotContain( + this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + ObjectEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.Contains); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new ObjectCollectionContainResult, IThat?>, TItem>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint( + expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), expected, + options, matchOptions).Invert()), + source, + options, + matchOptions); + } + + /// + /// Verifies that the collection does not contain the provided collection. + /// + public static StringCollectionContainResult, IThat?>> + DoesNotContain( + this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + StringEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.Contains); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new StringCollectionContainResult, IThat?>>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint( + expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, options, matchOptions).Invert()), + source, + options, + matchOptions); + } + private sealed class ContainConstraint( ExpectationBuilder expectationBuilder, string it, diff --git a/Source/aweXpect/That/Collections/ThatAsyncEnumerable.IsContainedIn.cs b/Source/aweXpect/That/Collections/ThatAsyncEnumerable.IsContainedIn.cs index 0501fb781..d02cfe959 100644 --- a/Source/aweXpect/That/Collections/ThatAsyncEnumerable.IsContainedIn.cs +++ b/Source/aweXpect/That/Collections/ThatAsyncEnumerable.IsContainedIn.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using aweXpect.Core; +using aweXpect.Core.Constraints; using aweXpect.Helpers; using aweXpect.Options; using aweXpect.Results; @@ -60,5 +61,56 @@ public static partial class ThatAsyncEnumerable options, matchOptions); } + + /// + /// Verifies that the collection is not contained in the provided collection. + /// + public static ObjectCollectionBeContainedInResult, IThat?>, TItem> + IsNotContainedIn( + this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + ObjectEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.IsContainedIn); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new + ObjectCollectionBeContainedInResult, IThat?>, TItem>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint(expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, + options, + matchOptions).Invert()), + source, + options, + matchOptions); + } + + /// + /// Verifies that the collection is not contained in the provided collection. + /// + public static StringCollectionBeContainedInResult, + IThat?>> + IsNotContainedIn( + this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + StringEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.IsContainedIn); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new StringCollectionBeContainedInResult, + IThat?>>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint(expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, + options, + matchOptions).Invert()), + source, + options, + matchOptions); + } } #endif diff --git a/Source/aweXpect/That/Collections/ThatAsyncEnumerable.cs b/Source/aweXpect/That/Collections/ThatAsyncEnumerable.cs index 1949dff2c..dd650c10c 100644 --- a/Source/aweXpect/That/Collections/ThatAsyncEnumerable.cs +++ b/Source/aweXpect/That/Collections/ThatAsyncEnumerable.cs @@ -344,6 +344,15 @@ public async Task IsMetBy(IAsyncEnumerable? actual, IEv _items = []; } + expectationBuilder.UpdateContexts(contexts => contexts + .Add(new ResultContext("Expected", + () => Formatter.Format(expected, typeof(TItem).GetFormattingOption(expected switch + { + ICollection coll => coll.Count, + ICountable countable => countable.Count, + _ => null, + })), + -2))); await foreach (TItem item in materializedEnumerable.WithCancellation(cancellationToken)) { if (_items?.Count < maximumNumber + 1) @@ -381,9 +390,7 @@ private string TooManyDeviationsError() sb.Append(It); sb.Append(" had more than "); sb.Append(2 * maximumNumberOfCollectionItems); - sb.Append(" deviations compared to "); - ValueFormatters.Format(Formatter, sb, expected?.Take(maximumNumberOfCollectionItems + 1), - FormattingOptions.MultipleLines); + sb.Append(" deviations"); return sb.ToString(); } diff --git a/Source/aweXpect/That/Collections/ThatEnumerable.Contains.cs b/Source/aweXpect/That/Collections/ThatEnumerable.Contains.cs index 51a3592fc..b16e3aa90 100644 --- a/Source/aweXpect/That/Collections/ThatEnumerable.Contains.cs +++ b/Source/aweXpect/That/Collections/ThatEnumerable.Contains.cs @@ -208,6 +208,49 @@ public static CountResult, IThat?>> quantifier); } + /// + /// Verifies that the collection does not contain the provided collection. + /// + public static ObjectCollectionContainResult, IThat?>, TItem> + DoesNotContain( + this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + ObjectEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.Contains); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new ObjectCollectionContainResult, IThat?>, TItem>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint(expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, + options, matchOptions).Invert()), + source, + options, + matchOptions); + } + + /// + /// Verifies that the collection does not contain the provided collection. + /// + public static StringCollectionContainResult, IThat?>> + DoesNotContain(this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + StringEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.Contains); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new StringCollectionContainResult, IThat?>>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint(expectationBuilder, it, grammars, doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, options, matchOptions).Invert()), + source, + options, + matchOptions); + } + private sealed class ContainConstraint( ExpectationBuilder expectationBuilder, string it, diff --git a/Source/aweXpect/That/Collections/ThatEnumerable.IsContainedIn.cs b/Source/aweXpect/That/Collections/ThatEnumerable.IsContainedIn.cs index 5a80873a7..436e6245b 100644 --- a/Source/aweXpect/That/Collections/ThatEnumerable.IsContainedIn.cs +++ b/Source/aweXpect/That/Collections/ThatEnumerable.IsContainedIn.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using aweXpect.Core; +using aweXpect.Core.Constraints; using aweXpect.Helpers; using aweXpect.Options; using aweXpect.Results; @@ -55,4 +56,50 @@ public static partial class ThatEnumerable options, matchOptions); } + /// + /// Verifies that the collection is not contained in the provided collection. + /// + public static ObjectCollectionBeContainedInResult, IThat?>, TItem> + IsNotContainedIn( + this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + ObjectEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.IsContainedIn); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new ObjectCollectionBeContainedInResult, IThat?>, TItem>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint(expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, + options, + matchOptions).Invert()), + source, + options, + matchOptions); + } + + /// + /// Verifies that the collection is not contained in the provided collection. + /// + public static StringCollectionBeContainedInResult, IThat?>> + IsNotContainedIn(this IThat?> source, + IEnumerable expected, + [CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") + { + StringEqualityOptions options = new(); + CollectionMatchOptions matchOptions = new(CollectionMatchOptions.EquivalenceRelations.IsContainedIn); + ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder; + return new StringCollectionBeContainedInResult, IThat?>>( + expectationBuilder.AddConstraint((it, grammars) => + new IsEqualToConstraint(expectationBuilder, it, grammars, + doNotPopulateThisValue.TrimCommonWhiteSpace(), + expected, + options, + matchOptions).Invert()), + source, + options, + matchOptions); + } } diff --git a/Source/aweXpect/That/Collections/ThatEnumerable.cs b/Source/aweXpect/That/Collections/ThatEnumerable.cs index beeaae4fd..178aaeeab 100644 --- a/Source/aweXpect/That/Collections/ThatEnumerable.cs +++ b/Source/aweXpect/That/Collections/ThatEnumerable.cs @@ -41,6 +41,15 @@ public ConstraintResult IsMetBy(IEnumerable? actual, IEvaluationContext c return this; } + expectationBuilder.UpdateContexts(contexts => contexts + .Add(new ResultContext("Expected", + () => Formatter.Format(expected, typeof(TItem).GetFormattingOption(expected switch + { + ICollection coll => coll.Count, + ICountable countable => countable.Count, + _ => null, + })), + -2))); IEnumerable materializedEnumerable = context.UseMaterializedEnumerable>(actual); ICollectionMatcher matcher = matchOptions.GetCollectionMatcher(expected); @@ -65,12 +74,13 @@ public ConstraintResult IsMetBy(IEnumerable? actual, IEvaluationContext c return this; } + expectationBuilder.AddCollectionContext(materializedEnumerable); Outcome = Outcome.Success; return this; } private string TooManyDeviationsError() - => $"{It} had more than {2 * Customize.aweXpect.Formatting().MaximumNumberOfCollectionItems.Get()} deviations compared to {Formatter.Format(expected, FormattingOptions.MultipleLines)}"; + => $"{It} had more than {2 * Customize.aweXpect.Formatting().MaximumNumberOfCollectionItems.Get()} deviations"; protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null) { @@ -101,8 +111,7 @@ protected override void AppendNegatedResult(StringBuilder stringBuilder, string? } else { - stringBuilder.Append(It).Append(" did in "); - Formatter.Format(stringBuilder, Actual, FormattingOptions.MultipleLines); + stringBuilder.Append(It).Append(" did"); } } } diff --git a/Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt b/Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt index 110d6d745..443c9fe6c 100644 --- a/Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt +++ b/Tests/aweXpect.Api.Tests/Expected/aweXpect_net8.0.txt @@ -67,7 +67,9 @@ namespace aweXpect public static aweXpect.Results.ObjectCollectionContainResult, aweXpect.Core.IThat?>, TItem> Contains(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CountResult, aweXpect.Core.IThat?>> Contains(this aweXpect.Core.IThat?> source, System.Func predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.StringEqualityTypeCountResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, string? unexpected) { } + public static aweXpect.Results.StringCollectionContainResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.ObjectCountResult, aweXpect.Core.IThat?>, TItem> DoesNotContain(this aweXpect.Core.IThat?> source, TItem unexpected) { } + public static aweXpect.Results.ObjectCollectionContainResult, aweXpect.Core.IThat?>, TItem> DoesNotContain(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CountResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, System.Func predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.StringEqualityResult, aweXpect.Core.IThat?>> DoesNotEndWith(this aweXpect.Core.IThat?> source, params string[] unexpected) { } public static aweXpect.Results.StringEqualityResult, aweXpect.Core.IThat?>> DoesNotEndWith(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } @@ -104,6 +106,8 @@ namespace aweXpect public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInAscendingOrder(this aweXpect.Core.IThat?> source, System.Func memberAccessor, [System.Runtime.CompilerServices.CallerArgumentExpression("memberAccessor")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInDescendingOrder(this aweXpect.Core.IThat?> source) { } public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInDescendingOrder(this aweXpect.Core.IThat?> source, System.Func memberAccessor, [System.Runtime.CompilerServices.CallerArgumentExpression("memberAccessor")] string doNotPopulateThisValue = "") { } + public static aweXpect.Results.StringCollectionBeContainedInResult, aweXpect.Core.IThat?>> IsNotContainedIn(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } + public static aweXpect.Results.ObjectCollectionBeContainedInResult, aweXpect.Core.IThat?>, TItem> IsNotContainedIn(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.AndOrResult, aweXpect.Core.IThat?>> IsNotEmpty(this aweXpect.Core.IThat?> source) { } public static aweXpect.Results.ObjectCollectionMatchWithToleranceResult, aweXpect.Core.IThat?>, System.DateTime, System.TimeSpan> IsNotEqualTo(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.ObjectCollectionMatchWithToleranceResult, aweXpect.Core.IThat?>, System.DateTime?, System.TimeSpan> IsNotEqualTo(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } @@ -357,7 +361,9 @@ namespace aweXpect public static aweXpect.Results.ObjectCollectionContainResult, aweXpect.Core.IThat?>, TItem> Contains(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CountResult, aweXpect.Core.IThat?>> Contains(this aweXpect.Core.IThat?> source, System.Func predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.StringEqualityTypeCountResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, string? unexpected) { } + public static aweXpect.Results.StringCollectionContainResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.ObjectCountResult, aweXpect.Core.IThat?>, TItem> DoesNotContain(this aweXpect.Core.IThat?> source, TItem unexpected) { } + public static aweXpect.Results.ObjectCollectionContainResult, aweXpect.Core.IThat?>, TItem> DoesNotContain(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CountResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, System.Func predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.StringEqualityResult, aweXpect.Core.IThat?>> DoesNotEndWith(this aweXpect.Core.IThat?> source, params string[] unexpected) { } public static aweXpect.Results.StringEqualityResult, aweXpect.Core.IThat?>> DoesNotEndWith(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } @@ -394,6 +400,8 @@ namespace aweXpect public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInAscendingOrder(this aweXpect.Core.IThat?> source, System.Func memberAccessor, [System.Runtime.CompilerServices.CallerArgumentExpression("memberAccessor")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInDescendingOrder(this aweXpect.Core.IThat?> source) { } public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInDescendingOrder(this aweXpect.Core.IThat?> source, System.Func memberAccessor, [System.Runtime.CompilerServices.CallerArgumentExpression("memberAccessor")] string doNotPopulateThisValue = "") { } + public static aweXpect.Results.StringCollectionBeContainedInResult, aweXpect.Core.IThat?>> IsNotContainedIn(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } + public static aweXpect.Results.ObjectCollectionBeContainedInResult, aweXpect.Core.IThat?>, TItem> IsNotContainedIn(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.AndOrResult, aweXpect.Core.IThat?>> IsNotEmpty(this aweXpect.Core.IThat?> source) { } public static aweXpect.Results.ObjectCollectionMatchWithToleranceResult, aweXpect.Core.IThat?>, System.DateTime, System.TimeSpan> IsNotEqualTo(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.ObjectCollectionMatchWithToleranceResult, aweXpect.Core.IThat?>, System.DateTime?, System.TimeSpan> IsNotEqualTo(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } diff --git a/Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt b/Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt index 939793615..6013c8d03 100644 --- a/Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt +++ b/Tests/aweXpect.Api.Tests/Expected/aweXpect_netstandard2.0.txt @@ -212,7 +212,9 @@ namespace aweXpect public static aweXpect.Results.ObjectCollectionContainResult, aweXpect.Core.IThat?>, TItem> Contains(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CountResult, aweXpect.Core.IThat?>> Contains(this aweXpect.Core.IThat?> source, System.Func predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.StringEqualityTypeCountResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, string? unexpected) { } + public static aweXpect.Results.StringCollectionContainResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.ObjectCountResult, aweXpect.Core.IThat?>, TItem> DoesNotContain(this aweXpect.Core.IThat?> source, TItem unexpected) { } + public static aweXpect.Results.ObjectCollectionContainResult, aweXpect.Core.IThat?>, TItem> DoesNotContain(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CountResult, aweXpect.Core.IThat?>> DoesNotContain(this aweXpect.Core.IThat?> source, System.Func predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.StringEqualityResult, aweXpect.Core.IThat?>> DoesNotEndWith(this aweXpect.Core.IThat?> source, params string[] unexpected) { } public static aweXpect.Results.StringEqualityResult, aweXpect.Core.IThat?>> DoesNotEndWith(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } @@ -249,6 +251,8 @@ namespace aweXpect public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInAscendingOrder(this aweXpect.Core.IThat?> source, System.Func memberAccessor, [System.Runtime.CompilerServices.CallerArgumentExpression("memberAccessor")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInDescendingOrder(this aweXpect.Core.IThat?> source) { } public static aweXpect.Results.CollectionOrderResult, aweXpect.Core.IThat?>> IsInDescendingOrder(this aweXpect.Core.IThat?> source, System.Func memberAccessor, [System.Runtime.CompilerServices.CallerArgumentExpression("memberAccessor")] string doNotPopulateThisValue = "") { } + public static aweXpect.Results.StringCollectionBeContainedInResult, aweXpect.Core.IThat?>> IsNotContainedIn(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } + public static aweXpect.Results.ObjectCollectionBeContainedInResult, aweXpect.Core.IThat?>, TItem> IsNotContainedIn(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.AndOrResult, aweXpect.Core.IThat?>> IsNotEmpty(this aweXpect.Core.IThat?> source) { } public static aweXpect.Results.ObjectCollectionMatchWithToleranceResult, aweXpect.Core.IThat?>, System.DateTime, System.TimeSpan> IsNotEqualTo(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } public static aweXpect.Results.ObjectCollectionMatchWithToleranceResult, aweXpect.Core.IThat?>, System.DateTime?, System.TimeSpan> IsNotEqualTo(this aweXpect.Core.IThat?> source, System.Collections.Generic.IEnumerable unexpected, [System.Runtime.CompilerServices.CallerArgumentExpression("unexpected")] string doNotPopulateThisValue = "") { } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs index 3e05167c4..65387c315 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.Contains.CollectionTests.cs @@ -25,20 +25,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -53,6 +41,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -76,6 +79,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -117,6 +127,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -179,6 +203,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -206,6 +240,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -256,6 +300,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -292,6 +343,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -331,6 +390,14 @@ contained item "c" at index 2 instead of "b" and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -367,6 +434,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -393,6 +468,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -424,20 +508,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -452,6 +524,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -475,6 +562,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -497,6 +591,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -538,6 +639,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -567,6 +682,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -594,6 +719,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -644,6 +779,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -728,6 +870,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -754,6 +904,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -785,20 +944,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -813,6 +960,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -836,6 +998,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -877,6 +1046,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -906,6 +1089,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -933,6 +1126,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -1005,6 +1208,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -1041,6 +1252,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -1077,6 +1296,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1103,6 +1330,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1134,20 +1370,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -1162,6 +1386,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1185,6 +1424,15 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] """); } @@ -1207,6 +1455,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -1248,6 +1503,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1277,6 +1546,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1304,6 +1583,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -1424,6 +1713,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1450,6 +1747,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1481,20 +1787,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -1509,6 +1803,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1534,6 +1843,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1575,6 +1891,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1606,6 +1936,16 @@ did not contain any additional items and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1633,6 +1973,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -1684,6 +2034,13 @@ did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1722,6 +2079,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -1762,6 +2127,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -1800,6 +2173,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1828,6 +2209,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1852,6 +2242,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -1871,20 +2268,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -1899,6 +2284,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1924,6 +2324,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1948,6 +2355,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -1989,6 +2403,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2018,6 +2446,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2045,6 +2483,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -2096,6 +2544,13 @@ did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2121,6 +2576,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2145,6 +2607,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2170,6 +2640,13 @@ but it did not contain any additional items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2194,6 +2671,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2219,6 +2704,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2245,6 +2737,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -2273,6 +2773,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -2297,6 +2806,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2316,20 +2832,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -2344,6 +2848,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2369,6 +2888,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2410,6 +2936,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2439,6 +2979,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2468,6 +3018,16 @@ did not contain any additional items and "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -2516,6 +3076,13 @@ but it did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2554,6 +3121,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2592,6 +3167,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2630,6 +3213,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -2658,6 +3249,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -2682,6 +3282,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2701,20 +3308,8 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] - + but it had more than 20 deviations + Collection: [ 1, @@ -2729,6 +3324,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2754,6 +3364,15 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] """); } @@ -2778,6 +3397,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -2819,6 +3445,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2848,6 +3488,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2877,6 +3527,16 @@ did not contain any additional items and "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -2925,6 +3585,13 @@ but it did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2950,6 +3617,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2974,6 +3648,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2999,6 +3681,13 @@ but it did not contain any additional items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -3023,6 +3712,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -3048,6 +3745,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -3074,6 +3778,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -3102,6 +3814,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -3126,6 +3847,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.CollectionTests.cs new file mode 100644 index 000000000..61873cea1 --- /dev/null +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.CollectionTests.cs @@ -0,0 +1,2548 @@ +#if NET8_0_OR_GREATER +using System.Collections.Generic; +using System.Linq; + +// ReSharper disable PossibleMultipleEnumeration + +namespace aweXpect.Tests; + +public sealed partial class ThatAsyncEnumerable +{ + public sealed partial class DoesNotContain + { + public sealed class InSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenSubjectIsNull_ShouldSucceed() + { + IAsyncEnumerable? subject = null; + + async Task Act() + => await That(subject).DoesNotContain([]); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class ProperlyInSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + } +} +#endif diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.Tests.cs index 39070772f..ede680702 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.DoesNotContain.Tests.cs @@ -9,7 +9,7 @@ namespace aweXpect.Tests; public sealed partial class ThatAsyncEnumerable { - public sealed class DoesNotContain + public sealed partial class DoesNotContain { public sealed class ItemTests { @@ -885,19 +885,6 @@ async Task Act() await That(Act).DoesNotThrow(); } - [Fact] - public async Task WhenPredicateIsNull_ShouldThrowArgumentNullException() - { - IAsyncEnumerable subject = Factory.GetAsyncFibonacciNumbers(); - - async Task Act() - => await That(subject).DoesNotContain(null!); - - await That(Act).Throws() - .WithParamName("predicate").And - .WithMessage("The predicate cannot be null.").AsPrefix(); - } - [Fact] public async Task WhenSubjectIsNull_ShouldFail() { diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsContainedIn.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsContainedIn.Tests.cs index c1762a77e..6942fbb2b 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsContainedIn.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsContainedIn.Tests.cs @@ -25,19 +25,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -53,6 +41,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -106,6 +109,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -167,6 +184,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -204,6 +231,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -232,6 +266,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -258,6 +299,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -283,6 +331,13 @@ but it contained item "c" at index 0 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -320,6 +375,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -357,6 +419,13 @@ but it contained item "a" at index 0 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -412,19 +481,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -440,6 +497,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -505,6 +577,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -533,6 +619,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -570,6 +666,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -598,6 +701,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -624,6 +734,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -739,19 +856,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -767,6 +872,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -820,6 +940,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -848,6 +982,16 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -885,6 +1029,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -913,6 +1064,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -950,6 +1108,13 @@ but it contained item "c" at index 3 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -987,6 +1152,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1024,6 +1196,13 @@ but it contained item "a" at index 1 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1079,19 +1258,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1107,6 +1274,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1172,6 +1354,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1200,8 +1396,18 @@ contained item "e" at index 4 that was not expected "d", "e" ] - """); - } + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] + """); + } [Fact] public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() @@ -1237,6 +1443,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1265,6 +1478,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1392,19 +1612,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1420,6 +1628,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1473,6 +1696,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1501,6 +1738,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1540,6 +1787,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1569,6 +1823,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1596,6 +1857,13 @@ contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1623,6 +1891,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1662,6 +1937,13 @@ contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1701,6 +1983,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1749,6 +2038,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -1768,19 +2064,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1796,6 +2080,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1861,6 +2160,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1889,6 +2202,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1928,6 +2251,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1957,6 +2287,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1984,6 +2321,13 @@ contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2009,6 +2353,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2033,6 +2384,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2058,6 +2417,13 @@ but it contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2082,6 +2448,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2107,6 +2481,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2155,6 +2536,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2174,19 +2562,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -2202,6 +2578,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2255,6 +2646,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2283,6 +2688,16 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2322,6 +2737,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2351,6 +2773,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2375,6 +2804,13 @@ but it contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2402,6 +2838,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2441,6 +2884,13 @@ contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2480,6 +2930,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2528,6 +2985,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2548,19 +3012,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -2576,6 +3028,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2644,6 +3111,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2673,6 +3154,16 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2714,6 +3205,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2744,6 +3242,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2769,6 +3274,13 @@ but it contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2795,6 +3307,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2820,6 +3339,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2846,6 +3373,13 @@ but it contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2871,6 +3405,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2897,6 +3439,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2948,6 +3497,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.Tests.cs index 873b1fba5..aa501fed8 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.Tests.cs @@ -24,7 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in order, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -40,6 +40,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -56,19 +59,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -84,6 +75,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -107,6 +113,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -159,6 +172,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -236,6 +263,16 @@ contained item "e" at index 4 instead of "y" and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -261,6 +298,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -289,6 +333,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -315,6 +366,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -340,6 +398,13 @@ but it contained item "c" at index 0 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -364,6 +429,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -389,6 +462,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -416,6 +496,14 @@ contained item "c" at index 2 instead of "b" and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -440,6 +528,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -466,6 +562,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -496,7 +601,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in order ignoring duplicates, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -512,6 +617,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -528,19 +636,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -556,6 +652,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -579,6 +690,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -601,6 +719,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -653,6 +778,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -685,6 +824,16 @@ contained item "e" at index 4 instead of "y" and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -710,6 +859,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -738,6 +894,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -764,6 +927,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -848,6 +1018,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -874,6 +1052,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -904,7 +1091,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in any order, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -920,6 +1107,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -936,19 +1126,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -964,6 +1142,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -987,6 +1180,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1039,6 +1239,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1071,6 +1285,16 @@ contained item "e" at index 4 that was not expected and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1096,6 +1320,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1124,6 +1355,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1161,6 +1399,13 @@ but it contained item "c" at index 3 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1185,6 +1430,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -1210,6 +1463,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1234,6 +1494,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -1259,6 +1527,13 @@ but it contained item "a" at index 1 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1283,6 +1558,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1309,6 +1592,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1339,7 +1631,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in any order ignoring duplicates, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -1355,6 +1647,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -1371,19 +1666,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1399,6 +1682,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1422,6 +1720,15 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] """); } @@ -1444,6 +1751,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -1496,6 +1810,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1528,6 +1856,16 @@ contained item "e" at index 4 that was not expected and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1553,6 +1891,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1581,6 +1926,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1677,6 +2029,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1703,6 +2063,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.WithinTests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.WithinTests.cs index 745a407fd..1cb823f81 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.WithinTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsEqualTo.WithinTests.cs @@ -42,6 +42,9 @@ contained item 2.3 at index 1 that was not expected and Collection: [1.1, 2.3, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } } @@ -77,6 +80,9 @@ contained item 2.3 at index 2 that was not expected and Collection: [1.1, , 2.3, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } } @@ -123,6 +129,9 @@ contained item 2.3 at index 1 that was not expected and Collection: [1.1, 2.3, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } } @@ -169,6 +178,9 @@ contained item 2.3 at index 2 that was not expected and Collection: [1.1, , 2.3, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } } @@ -215,6 +227,9 @@ contained item 2.3 at index 1 that was not expected and Collection: [1.1, 2.3, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } } @@ -261,6 +276,9 @@ contained item 2.3 at index 2 that was not expected and Collection: [1.1, , 2.3, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } } @@ -308,6 +326,9 @@ but it {Formatter.Format(now.AddHours(2))}, {Formatter.Format(now.AddHours(3))} ] + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } } @@ -356,6 +377,9 @@ but it {Formatter.Format(now.AddHours(2))}, {Formatter.Format(now.AddHours(3))} ] + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotContainedIn.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotContainedIn.Tests.cs new file mode 100644 index 000000000..10c4a066e --- /dev/null +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotContainedIn.Tests.cs @@ -0,0 +1,2819 @@ +#if NET8_0_OR_GREATER +using System.Collections.Generic; +using System.Linq; + +// ReSharper disable PossibleMultipleEnumeration + +namespace aweXpect.Tests; + +public sealed partial class ThatAsyncEnumerable +{ + public sealed class IsNotContainedIn + { + public sealed class InSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).IsNotContainedIn(expected!); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenSubjectIsNull_ShouldSucceed() + { + IAsyncEnumerable? subject = null; + + async Task Act() + => await That(subject).IsNotContainedIn([]); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class ProperlyInSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 11)); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(Enumerable.Range(1, 10)); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IAsyncEnumerable subject = ToAsyncEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + } +} +#endif diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.Tests.cs index d6ee94e38..0d41f82c2 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.Tests.cs @@ -240,6 +240,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -375,6 +382,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -399,6 +413,14 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -424,6 +446,13 @@ but it did "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -448,6 +477,14 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -473,6 +510,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -521,6 +565,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -631,6 +682,13 @@ but it did "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -739,6 +797,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -861,6 +926,13 @@ but it did "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -886,6 +958,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -910,6 +989,14 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -935,6 +1022,13 @@ but it did "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -959,6 +1053,14 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -984,6 +1086,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1032,6 +1141,13 @@ but it did "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -1059,6 +1175,13 @@ but it did "bar", "baz" ] + + Expected: + [ + "*oo", + "*a?", + "?a?" + ] """); } @@ -1084,6 +1207,13 @@ but it did "b", " c" ] + + Expected: + [ + "a", + " b", + "c" + ] """); } @@ -1109,6 +1239,13 @@ but it did "b", "c " ] + + Expected: + [ + "a", + "b ", + "c" + ] """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.WithinTests.cs b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.WithinTests.cs index d130469f9..3f9e21f89 100644 --- a/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.WithinTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.IsNotEqualTo.WithinTests.cs @@ -29,6 +29,9 @@ but it did Collection: [1.1, 2.1, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } @@ -62,6 +65,9 @@ but it did Collection: [1.1, , 2.1, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } @@ -95,6 +101,9 @@ but it did Collection: [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -114,6 +123,9 @@ but it did Collection: [1.1, 2.1, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } @@ -147,6 +159,9 @@ but it did Collection: [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -166,6 +181,9 @@ but it did Collection: [1.1, , 2.1, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } @@ -199,6 +217,9 @@ but it did Collection: [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -218,6 +239,9 @@ but it did Collection: [1.1, 2.1, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } @@ -251,6 +275,9 @@ but it did Collection: [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -270,6 +297,9 @@ but it did Collection: [1.1, , 2.1, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } @@ -311,6 +341,9 @@ but it did {Formatter.Format(now.AddHours(2))}, {Formatter.Format(now.AddHours(3))} ] + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } @@ -357,6 +390,9 @@ but it did {Formatter.Format(now.AddHours(2))}, {Formatter.Format(now.AddHours(3))} ] + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs index c12abe5da..29c9e1ed2 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.Contains.CollectionTests.cs @@ -24,19 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -52,6 +40,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -75,6 +78,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -116,6 +126,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -178,6 +202,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -205,6 +239,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -255,6 +299,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -291,6 +342,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -330,6 +389,14 @@ contained item "c" at index 2 instead of "b" and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -366,6 +433,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -392,6 +467,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -424,19 +508,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -452,6 +524,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -475,6 +562,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -497,6 +591,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -538,6 +639,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -567,6 +682,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -594,6 +719,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -644,6 +779,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -728,6 +870,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -754,6 +904,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -785,19 +944,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -813,6 +960,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -836,6 +998,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -877,6 +1046,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -906,6 +1089,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -933,6 +1126,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -1005,11 +1208,19 @@ Expected that subject "b", "c" ] - """); - } - - [Fact] - public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() { IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); string[] expected = ["a", "b", "c",]; @@ -1041,6 +1252,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -1077,6 +1296,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1103,6 +1330,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1135,19 +1371,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1163,6 +1387,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1186,6 +1425,15 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] """); } @@ -1208,6 +1456,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -1249,6 +1504,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1278,6 +1547,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1305,6 +1584,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -1425,6 +1714,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1451,6 +1748,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1482,19 +1788,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1510,6 +1804,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1535,6 +1844,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1576,6 +1892,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1607,6 +1937,16 @@ did not contain any additional items and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1634,6 +1974,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -1685,6 +2035,13 @@ did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1723,6 +2080,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -1763,6 +2128,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -1801,6 +2174,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1829,6 +2210,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1854,6 +2244,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -1873,19 +2270,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1901,6 +2286,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1926,6 +2326,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1950,6 +2357,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -1991,6 +2405,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2020,6 +2448,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2047,6 +2485,16 @@ Expected that subject "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -2098,6 +2546,13 @@ did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2123,6 +2578,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2147,6 +2609,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2172,6 +2642,13 @@ but it did not contain any additional items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2196,6 +2673,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2221,6 +2706,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2247,6 +2739,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -2273,7 +2773,16 @@ did not contain any additional items and [ "a", "b", - "c" + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" ] """); } @@ -2299,6 +2808,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2318,19 +2834,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -2346,6 +2850,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2371,6 +2890,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2412,6 +2938,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2441,6 +2981,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2470,6 +3020,16 @@ did not contain any additional items and "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -2518,6 +3078,13 @@ but it did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2556,6 +3123,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2594,6 +3169,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2632,6 +3215,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -2660,6 +3251,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -2685,6 +3285,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2704,19 +3311,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject contains collection expected and at least one additional item in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -2732,6 +3327,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2757,6 +3367,15 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] """); } @@ -2781,6 +3400,13 @@ did not contain any additional items and Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -2822,6 +3448,20 @@ Expected that subject 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2851,6 +3491,16 @@ Expected that subject "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2880,6 +3530,16 @@ did not contain any additional items and "c", "d" ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] """); } @@ -2928,6 +3588,13 @@ but it did not contain any additional items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2953,6 +3620,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2977,6 +3651,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -3002,6 +3684,13 @@ but it did not contain any additional items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -3026,6 +3715,14 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -3051,6 +3748,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -3077,6 +3781,14 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -3105,6 +3817,15 @@ did not contain any additional items and "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -3129,6 +3850,13 @@ but it did not contain any additional items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -3146,10 +3874,10 @@ async Task Act() => await That(subject).Contains([regex,]).AsRegex(); await That(Act).Throws().OnlyIf(!expectSuccess) - .WithMessage($""" + .WithMessage($$""" Expected that subject contains collection [regex,] in order as regex, - but it lacked 1 of 1 expected items: "{regex}" + but it lacked 1 of 1 expected items: "{{regex}}" Collection: [ @@ -3157,6 +3885,11 @@ Expected that subject "bar", "baz" ] + + Expected: + [ + "[g-h]{1}[o]*" + ] """); } @@ -3182,6 +3915,11 @@ Expected that subject "bar", "baz" ] + + Expected: + [ + "f??o" + ] """); } @@ -3207,6 +3945,11 @@ Expected that subject "bar", "baz" ] + + Expected: + [ + "*oo" + ] """); } @@ -3232,6 +3975,11 @@ Expected that subject "bar", "baz" ] + + Expected: + [ + "goo" + ] """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.CollectionTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.CollectionTests.cs new file mode 100644 index 000000000..458ac7a8a --- /dev/null +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.CollectionTests.cs @@ -0,0 +1,2558 @@ +using System.Collections.Generic; +using System.Linq; + +// ReSharper disable PossibleMultipleEnumeration + +namespace aweXpect.Tests; + +public sealed partial class ThatEnumerable +{ + public sealed partial class DoesNotContain + { + public sealed class InSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).DoesNotContain(expected!); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenSubjectIsNull_ShouldSucceed() + { + IEnumerable? subject = null; + + async Task Act() + => await That(subject).DoesNotContain([]); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class ProperlyInSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithAdditionalItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + does not contain collection expected and at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "d", + "e" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).DoesNotContain(expected).Properly().InAnyOrder() + .IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + } +} diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.Tests.cs index 6df425f95..09a1bed33 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.DoesNotContain.Tests.cs @@ -8,7 +8,7 @@ namespace aweXpect.Tests; public sealed partial class ThatEnumerable { - public sealed class DoesNotContain + public sealed partial class DoesNotContain { public sealed class ItemTests { @@ -923,19 +923,6 @@ async Task Act() await That(Act).DoesNotThrow(); } - [Fact] - public async Task WhenPredicateIsNull_ShouldThrowArgumentNullException() - { - IEnumerable subject = Factory.GetFibonacciNumbers(); - - async Task Act() - => await That(subject).DoesNotContain(null!); - - await That(Act).Throws() - .WithParamName("predicate").And - .WithMessage("The predicate cannot be null.").AsPrefix(); - } - [Fact] public async Task WhenSubjectIsNull_ShouldFail() { diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsContainedIn.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsContainedIn.Tests.cs index 7b0365a82..e8d87a694 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsContainedIn.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsContainedIn.Tests.cs @@ -24,19 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -52,6 +40,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -105,6 +108,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -166,6 +183,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -203,6 +230,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -231,6 +265,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -257,6 +298,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -282,6 +330,13 @@ but it contained item "c" at index 0 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -319,6 +374,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -356,6 +418,13 @@ but it contained item "a" at index 0 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -412,19 +481,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -440,6 +497,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -505,6 +577,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -533,6 +619,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -570,6 +666,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -598,6 +701,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -624,6 +734,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -739,19 +856,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -767,6 +872,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -820,6 +940,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -848,6 +982,16 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -885,6 +1029,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -913,6 +1064,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -950,6 +1108,13 @@ but it contained item "c" at index 3 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -987,6 +1152,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1024,6 +1196,13 @@ but it contained item "a" at index 1 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1080,19 +1259,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1108,6 +1275,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1173,6 +1355,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1201,8 +1397,18 @@ contained item "e" at index 4 that was not expected "d", "e" ] - """); - } + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] + """); + } [Fact] public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldSucceed() @@ -1238,6 +1444,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1266,6 +1479,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1393,19 +1613,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1421,6 +1629,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1474,6 +1697,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1502,6 +1739,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1541,6 +1788,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1570,6 +1824,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1597,6 +1858,13 @@ contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1624,6 +1892,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1663,6 +1938,13 @@ contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1702,6 +1984,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1751,6 +2040,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -1770,19 +2066,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1798,6 +2082,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1863,6 +2162,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1891,6 +2204,16 @@ contained item "e" at index 4 instead of "y" "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1930,6 +2253,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1959,6 +2289,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1986,6 +2323,13 @@ contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2011,6 +2355,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2035,6 +2386,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2060,6 +2419,13 @@ but it contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2084,6 +2450,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2109,6 +2483,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2157,6 +2538,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2176,19 +2564,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -2204,6 +2580,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2257,6 +2648,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2285,6 +2690,16 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2324,6 +2739,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2353,6 +2775,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2377,6 +2806,13 @@ but it contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2404,6 +2840,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2443,6 +2886,13 @@ contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2482,6 +2932,13 @@ contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2531,6 +2988,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } @@ -2551,19 +3015,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is contained in collection expected which has at least one additional item in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -2579,6 +3031,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -2647,6 +3114,20 @@ contained item 10 at index 9 that was not expected 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -2676,6 +3157,16 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -2717,6 +3208,13 @@ contained all expected items "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2747,6 +3245,13 @@ contained all expected items "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2772,6 +3277,13 @@ but it contained all expected items "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2798,6 +3310,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2823,6 +3342,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -2849,6 +3376,13 @@ but it contained all expected items "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2874,6 +3408,14 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -2900,6 +3442,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -2951,6 +3500,13 @@ but it contained all expected items "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.Tests.cs index bce47c464..d2c4e435c 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.Tests.cs @@ -23,7 +23,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in order, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -39,6 +39,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -56,19 +59,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -84,6 +75,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -107,6 +113,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -159,6 +172,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -236,6 +263,16 @@ contained item "e" at index 4 instead of "y" and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -261,6 +298,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -289,6 +333,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -315,6 +366,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -339,6 +397,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -364,6 +430,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -391,6 +464,14 @@ contained item "c" at index 2 instead of "b" and "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -416,6 +497,13 @@ but it contained item "a" at index 0 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -440,6 +528,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -466,6 +562,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -497,7 +602,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in order ignoring duplicates, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -513,6 +618,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -529,19 +637,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -557,6 +653,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -580,6 +691,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -602,6 +720,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -654,6 +779,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -686,6 +825,16 @@ contained item "e" at index 4 instead of "y" and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -711,6 +860,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -739,6 +895,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -765,6 +928,13 @@ contained item "b" at index 2 instead of "c" "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -837,6 +1007,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -863,6 +1041,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -893,7 +1080,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in any order, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -909,6 +1096,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -925,19 +1115,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in any order, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -953,6 +1131,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -976,6 +1169,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1028,6 +1228,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1060,6 +1274,16 @@ contained item "e" at index 4 that was not expected and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1085,6 +1309,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1113,6 +1344,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1149,6 +1387,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -1174,6 +1420,13 @@ but it contained item "c" at index 3 that was not expected "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1198,6 +1451,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] """); } @@ -1223,6 +1484,13 @@ but it contained item "a" at index 1 that was not expected "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1247,6 +1515,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1273,6 +1549,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } @@ -1304,7 +1589,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection [] in any order ignoring duplicates, - but it had more than 20 deviations compared to [] + but it had more than 20 deviations Collection: [ @@ -1320,6 +1605,9 @@ but it had more than 20 deviations compared to [] 10, (… and maybe others) ] + + Expected: + [] """); } @@ -1337,19 +1625,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject matches collection expected in any order ignoring duplicates, - but it had more than 20 deviations compared to [ - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - … - ] + but it had more than 20 deviations Collection: [ @@ -1365,6 +1641,21 @@ but it had more than 20 deviations compared to [ 10, … ] + + Expected: + [ + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + … + ] """); } @@ -1388,6 +1679,15 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] """); } @@ -1410,6 +1710,13 @@ Expected that subject Collection: [] + + Expected: + [ + "a", + "a", + "b" + ] """); } @@ -1462,6 +1769,20 @@ contained item 10 at index 9 that was not expected and 9, 10 ] + + Expected: + [ + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110 + ] """); } @@ -1494,6 +1815,16 @@ contained item "e" at index 4 that was not expected and "d", "e" ] + + Expected: + [ + "a", + "b", + "c", + "x", + "y", + "z" + ] """); } @@ -1519,6 +1850,13 @@ but it contained item "d" at index 3 that was not expected "c", "d" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1547,6 +1885,13 @@ contained item "e" at index 4 that was not expected "d", "e" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -1631,6 +1976,14 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] """); } @@ -1657,6 +2010,15 @@ Expected that subject "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] """); } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.WithinTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.WithinTests.cs index 4bc650440..42d5f0bab 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.WithinTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsEqualTo.WithinTests.cs @@ -41,6 +41,9 @@ contained item 2.3 at index 1 that was not expected and Collection: [1.1, 2.3, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } } @@ -76,6 +79,9 @@ contained item 2.3 at index 2 that was not expected and Collection: [1.1, , 2.3, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } } @@ -122,6 +128,9 @@ contained item 2.3 at index 1 that was not expected and Collection: [1.1, 2.3, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } } @@ -168,6 +177,9 @@ contained item 2.3 at index 2 that was not expected and Collection: [1.1, , 2.3, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } } @@ -214,6 +226,9 @@ contained item 2.3 at index 1 that was not expected and Collection: [1.1, 2.3, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } } @@ -260,6 +275,9 @@ contained item 2.3 at index 2 that was not expected and Collection: [1.1, , 2.3, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } } @@ -307,6 +325,9 @@ but it {Formatter.Format(now.AddHours(2))}, {Formatter.Format(now.AddHours(3))} ] + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } } @@ -355,6 +376,9 @@ but it {Formatter.Format(now.AddHours(2))}, {Formatter.Format(now.AddHours(3))} ] + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotContainedIn.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotContainedIn.Tests.cs new file mode 100644 index 000000000..954f98188 --- /dev/null +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotContainedIn.Tests.cs @@ -0,0 +1,2817 @@ +using System.Collections.Generic; +using System.Linq; + +// ReSharper disable PossibleMultipleEnumeration + +namespace aweXpect.Tests; + +public sealed partial class ThatEnumerable +{ + public sealed class IsNotContainedIn + { + public sealed class InSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenExpectedIsNull_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable? expected = null; + + async Task Act() + => await That(subject).IsNotContainedIn(expected!); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WhenSubjectIsNull_ShouldSucceed() + { + IEnumerable? subject = null; + + async Task Act() + => await That(subject).IsNotContainedIn([]); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class InAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "c", + "b" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "c", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + } + + public sealed class ProperlyInSameOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInSameOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [] + + Expected: + [ + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "a", + "b", + "c" + ] + """); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder(); + + await That(Act).DoesNotThrow(); + } + } + + public sealed class ProperlyInAnyOrderIgnoringDuplicatesTests + { + [Fact] + public async Task CompletelyDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 11); + IEnumerable expected = Enumerable.Range(100, 11); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task EmptyCollection_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b", "c", "a",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b", + "c", + "a" + ] + """); + } + + [Fact] + public async Task EmptyCollectionWithDuplicatesInExpected_ShouldFail() + { + IEnumerable subject = ToEnumerable(Array.Empty()); + string[] expected = ["a", "a", "b",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [] + + Expected: + [ + "a", + "a", + "b" + ] + """); + } + + [Fact] + public async Task VeryDifferentCollections_ShouldSucceed() + { + IEnumerable subject = Enumerable.Range(1, 10); + IEnumerable expected = Enumerable.Range(101, 10); + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalAndMissingItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c", "x", "y", "z",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalExpectedItemAtBeginningAndEnd_ShouldFail() + { + IEnumerable subject = ToEnumerable(["b", "b", "c", "d",]); + string[] expected = ["a", "b", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "b", + "b", + "c", + "d" + ] + + Expected: + [ + "a", + "b", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithAdditionalItem_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithAdditionalItems_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "d", "e",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithCollectionInDifferentOrder_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "c", "b",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtBeginOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["c", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesAtEndOfSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInExpected_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithDuplicatesInSubject_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + + [Fact] + public async Task WithMissingItem_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d" + ] + """); + } + + [Fact] + public async Task WithMissingItems_ShouldFail() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c", "d", "e",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not contained in collection expected which has at least one additional item in any order ignoring duplicates, + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", + "b", + "c", + "d", + "e" + ] + """); + } + + [Fact] + public async Task WithSameCollection_ShouldSucceed() + { + IEnumerable subject = ToEnumerable(["a", "b", "c",]); + string[] expected = ["a", "b", "c",]; + + async Task Act() + => await That(subject).IsNotContainedIn(expected).Properly().InAnyOrder().IgnoringDuplicates(); + + await That(Act).DoesNotThrow(); + } + } + } +} diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.Tests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.Tests.cs index 202dde780..837b512da 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.Tests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.Tests.cs @@ -231,7 +231,17 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order, - but it did in [ + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ "a", "b", "c" @@ -362,12 +372,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "c", "a", "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -384,11 +404,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -405,12 +436,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "b", "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -427,7 +468,18 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", "a", "b", "c" @@ -448,12 +500,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "a", "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -494,7 +556,17 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ "a", "b", "c" @@ -601,11 +673,21 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order, - but it did in [ + but it did + + Collection: + [ "a", "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -706,7 +788,17 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order, - but it did in [ + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ "a", "b", "c" @@ -825,11 +917,21 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "c", "b" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -846,12 +948,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "c", "a", "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -868,11 +980,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "b", "c" ] + + Expected: + [ + "a", + "b", + "c", + "c" + ] """); } @@ -889,12 +1012,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "b", "c", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -911,7 +1044,18 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ + "a", "a", "b", "c" @@ -932,12 +1076,22 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ "a", "a", "b", "c" ] + + Expected: + [ + "a", + "b", + "c" + ] """); } @@ -978,7 +1132,17 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in any order ignoring duplicates, - but it did in [ + but it did + + Collection: + [ + "a", + "b", + "c" + ] + + Expected: + [ "a", "b", "c" @@ -1002,11 +1166,21 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order as wildcard, - but it did in [ + but it did + + Collection: + [ "foo", "bar", "baz" ] + + Expected: + [ + "*oo", + "*a?", + "?a?" + ] """); } @@ -1024,11 +1198,21 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring leading white-space, - but it did in [ + but it did + + Collection: + [ " a", "b", " c" ] + + Expected: + [ + "a", + " b", + "c" + ] """); } @@ -1046,11 +1230,21 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection unexpected in order ignoring trailing white-space, - but it did in [ + but it did + + Collection: + [ "a ", "b", "c " ] + + Expected: + [ + "a", + "b ", + "c" + ] """); } } diff --git a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.WithinTests.cs b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.WithinTests.cs index e32653bb3..fcb40d964 100644 --- a/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.WithinTests.cs +++ b/Tests/aweXpect.Tests/Collections/ThatEnumerable.IsNotEqualTo.WithinTests.cs @@ -24,11 +24,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0m, 2.0m, 3.0m,] in any order ± 0.2, - but it did in [ - 1.1, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, 2.1, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } @@ -58,12 +60,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0m, null, 2.0m, 3.0m,] in order ± 0.2, - but it did in [ - 1.1, - , - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, , 2.1, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } @@ -93,12 +96,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0, double.NaN, 2.0, 3.0,] in any order ± 0.2, - but it did in [ - 1.1, - NaN, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -114,11 +118,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0, 2.0, 3.0,] in order ± 0.2, - but it did in [ - 1.1, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, 2.1, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } @@ -148,12 +154,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0, double.NaN, 2.0, 3.0,] in any order ± 0.2, - but it did in [ - 1.1, - NaN, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -169,12 +176,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0, null, 2.0, 3.0,] in any order ± 0.2, - but it did in [ - 1.1, - , - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, , 2.1, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } @@ -204,12 +212,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0F, float.NaN, 2.0F, 3.0F,] in any order ± 0.2, - but it did in [ - 1.1, - NaN, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -225,11 +234,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0F, 2.0F, 3.0F,] in any order ± 0.2, - but it did in [ - 1.1, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, 2.1, 3.1] + + Expected: + [1.0, 2.0, 3.0] """); } @@ -259,12 +270,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0F, float.NaN, 2.0F, 3.0F,] in any order ± 0.2, - but it did in [ - 1.1, - NaN, - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, NaN, 2.1, 3.1] + + Expected: + [1.0, NaN, 2.0, 3.0] """); } @@ -280,12 +292,13 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not match collection [1.0F, null, 2.0F, 3.0F,] in any order ± 0.2, - but it did in [ - 1.1, - , - 2.1, - 3.1 - ] + but it did + + Collection: + [1.1, , 2.1, 3.1] + + Expected: + [1.0, , 2.0, 3.0] """); } @@ -319,7 +332,13 @@ await That(Act).Throws() .WithMessage($""" Expected that subject does not match collection expected in any order within 1:00, - but it did in {Formatter.Format(subject, FormattingOptions.MultipleLines)} + but it did + + Collection: + {Formatter.Format(subject, FormattingOptions.MultipleLines)} + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); } @@ -357,7 +376,13 @@ await That(Act).Throws() .WithMessage($""" Expected that subject does not match collection expected in any order within 1:00, - but it did in {Formatter.Format(subject, FormattingOptions.MultipleLines)} + but it did + + Collection: + {Formatter.Format(subject, FormattingOptions.MultipleLines)} + + Expected: + {Formatter.Format(expected, FormattingOptions.MultipleLines)} """); }