瀏覽代碼

Add test for MoveNext extension method

Oren Novotny 9 年之前
父節點
當前提交
ff6311d083

+ 12 - 3
Ix.NET/Source/Tests/AsyncTests.Bugs.cs

@@ -213,7 +213,7 @@ namespace Tests
         /// <summary>
         /// Waits WaitTimeoutMs or until cancellation is requested. If cancellation was not requested, MoveNext returns true.
         /// </summary>
-        private sealed class CancellationTestAsyncEnumerable : IAsyncEnumerable<int>
+        internal sealed class CancellationTestAsyncEnumerable : IAsyncEnumerable<int>
         {
             private readonly int iterationsBeforeDelay;
 
@@ -221,9 +221,12 @@ namespace Tests
             {
                 this.iterationsBeforeDelay = iterationsBeforeDelay;
             }
-            public IAsyncEnumerator<int> GetEnumerator() => new TestEnumerator(iterationsBeforeDelay);
+            IAsyncEnumerator<int> IAsyncEnumerable<int>.GetEnumerator() => GetEnumerator();
 
-            private sealed class TestEnumerator : IAsyncEnumerator<int>
+            public TestEnumerator GetEnumerator() => new TestEnumerator(iterationsBeforeDelay);
+
+
+            internal sealed class TestEnumerator : IAsyncEnumerator<int>
             {
                 private readonly int iterationsBeforeDelay;
 
@@ -236,10 +239,16 @@ namespace Tests
                 {
                 }
 
+                public CancellationToken LastToken { get; private set; }
+                public bool MoveNextWasCalled { get; private set; }
+
                 public int Current => i;
                 
                 public async Task<bool> MoveNext(CancellationToken cancellationToken)
                 {
+                    LastToken = cancellationToken;
+                    MoveNextWasCalled = true;
+                  
                     i++;
                     if (Current >= iterationsBeforeDelay)
                     {

+ 0 - 8
Ix.NET/Source/Tests/AsyncTests.Creation.cs

@@ -12,14 +12,6 @@ using System.Threading;
 
 namespace Tests
 {
-    static class Ext
-    {
-        public static Task<bool> MoveNext<T>(this IAsyncEnumerator<T> enumerator)
-        {
-            return enumerator.MoveNext(CancellationToken.None);
-        }
-    }
-
     public partial class AsyncTests
     {
         [Fact]

+ 12 - 0
Ix.NET/Source/Tests/AsyncTests.Single.cs

@@ -14,6 +14,18 @@ namespace Tests
 {
     public partial class AsyncTests
     {
+        [Fact]
+        public void MoveNextExtension()
+        {
+            var enumerable = new CancellationTestAsyncEnumerable();
+            var en = enumerable.GetEnumerator();
+
+            en.MoveNext();
+
+            Assert.True(en.MoveNextWasCalled);
+            Assert.Equal(CancellationToken.None, en.LastToken);
+        }
+
         [Fact]
         public void Select_Null()
         {