diff --git a/MoreLinq.Test/AssertTest.cs b/MoreLinq.Test/AssertTest.cs index ecd288ce6..72ace92ae 100644 --- a/MoreLinq.Test/AssertTest.cs +++ b/MoreLinq.Test/AssertTest.cs @@ -33,14 +33,15 @@ public void AssertIsLazy() [Test] public void AssertSequenceWithValidAllElements() { - var source = new[] { 2, 4, 6, 8 }; - source.Assert(n => n % 2 == 0).AssertSequenceEqual(source); + var xs = new[] { 2, 4, 6, 8 }; + using var source = TestingSequence.Of(xs); + source.Assert(n => n % 2 == 0).AssertSequenceEqual(xs); } [Test] public void AssertSequenceWithValidSomeInvalidElements() { - var source = new[] { 2, 4, 6, 7, 8, 9 }; + using var source = TestingSequence.Of(2, 4, 6, 7, 8, 9); Assert.That(() => source.Assert(n => n % 2 == 0).Consume(), Throws.InvalidOperationException); } @@ -48,7 +49,7 @@ public void AssertSequenceWithValidSomeInvalidElements() [Test] public void AssertSequenceWithInvalidElementsAndCustomErrorReturningNull() { - var source = new[] { 2, 4, 6, 7, 8, 9 }; + using var source = TestingSequence.Of(2, 4, 6, 7, 8, 9); Assert.That(() => source.Assert(n => n % 2 == 0, _ => null!).Consume(), Throws.InvalidOperationException); } @@ -56,7 +57,7 @@ public void AssertSequenceWithInvalidElementsAndCustomErrorReturningNull() [Test] public void AssertSequenceWithInvalidElementsAndCustomError() { - var source = new[] { 2, 4, 6, 7, 8, 9 }; + using var source = TestingSequence.Of(2, 4, 6, 7, 8, 9); Assert.That(() => source.Assert(n => n % 2 == 0, n => new ValueException(n)).Consume(), Throws.TypeOf() diff --git a/MoreLinq.Test/AtLeastTest.cs b/MoreLinq.Test/AtLeastTest.cs index 83f6093ad..cb92815ce 100644 --- a/MoreLinq.Test/AtLeastTest.cs +++ b/MoreLinq.Test/AtLeastTest.cs @@ -17,6 +17,7 @@ namespace MoreLinq.Test { + using System; using NUnit.Framework; using System.Collections.Generic; @@ -49,8 +50,13 @@ from e in new[] .SetName($"{{m}}({k}[{e.Size}], {e.Count})"); [TestCaseSource(nameof(AtLeastSource))] - public bool AtLeast(SourceKind sourceKind, int sequenceSize, int atLeastAssertCount) => - Enumerable.Range(0, sequenceSize).ToSourceKind(sourceKind).AtLeast(atLeastAssertCount); + public bool AtLeast(SourceKind sourceKind, int sequenceSize, int atLeastAssertCount) + { + var xs = Enumerable.Range(0, sequenceSize); + var source = xs.ToSourceKind(sourceKind); + using (source as IDisposable) // primarily for `TestingSequence<>` + return source.AtLeast(atLeastAssertCount); + } [Test] public void AtLeastDoesNotIterateUnnecessaryElements() diff --git a/MoreLinq.Test/TestExtensions.cs b/MoreLinq.Test/TestExtensions.cs index 706641f1b..4c9c52858 100644 --- a/MoreLinq.Test/TestExtensions.cs +++ b/MoreLinq.Test/TestExtensions.cs @@ -92,14 +92,14 @@ internal static IEnumerable ToSourceKind(this IEnumerable input, Source sourceKind switch #pragma warning restore IDE0072 // Add missing cases { - SourceKind.Sequence => input.Select(x => x), + SourceKind.Sequence => input.AsTestingSequence(), var kind => input.ToList().AsSourceKind(kind) }; internal static IEnumerable AsSourceKind(this List input, SourceKind sourceKind) => sourceKind switch { - SourceKind.Sequence => input.Select(x => x), + SourceKind.Sequence => input.AsTestingSequence(), SourceKind.BreakingList => new BreakingList(input), SourceKind.BreakingReadOnlyList => new BreakingReadOnlyList(input), SourceKind.BreakingCollection => new BreakingCollection(input),