فهرست منبع

Added unit tests for new ToAsyncEnumerable overloads.

Daniel Weber 11 سال پیش
والد
کامیت
8aaf7c2c79
1فایلهای تغییر یافته به همراه41 افزوده شده و 0 حذف شده
  1. 41 0
      Ix.NET/Source/Tests/AsyncTests.Conversions.cs

+ 41 - 0
Ix.NET/Source/Tests/AsyncTests.Conversions.cs

@@ -4,6 +4,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Threading.Tasks;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using System.Threading;
 
@@ -95,6 +96,46 @@ namespace Tests
             AssertThrows<Exception>(() => e.MoveNext().Wait(), ex_ => ((AggregateException)ex_).InnerExceptions.Single() == ex);
         }
 
+#if HAS_AWAIT
+        [TestMethod]
+        public async Task ToAsyncEnumerable_with_completed_task()
+        {
+            var task = Task.FromResult(36);
+
+            var xs = task.ToAsyncEnumerable();
+            var e = xs.GetEnumerator();
+
+            Assert.IsTrue(e.MoveNext().Result);
+            Assert.AreEqual(36, e.Current);
+            Assert.IsFalse(e.MoveNext().Result);
+        }
+
+        [TestMethod]
+        public async Task ToAsyncEnumerable_with_faulted_task()
+        {
+            var ex = new InvalidOperationException();
+            var tcs = new TaskCompletionSource<int>();
+            tcs.SetException(ex);
+
+            var xs = tcs.Task.ToAsyncEnumerable();
+            var e = xs.GetEnumerator();
+
+            AssertThrows<Exception>(() => e.MoveNext().Wait(), ex_ => ((AggregateException)ex_).InnerExceptions.Single() == ex);
+        }
+
+        [TestMethod]
+        public async Task ToAsyncEnumerable_with_canceled_task()
+        {
+            var tcs = new TaskCompletionSource<int>();
+            tcs.SetCanceled();
+
+            var xs = tcs.Task.ToAsyncEnumerable();
+            var e = xs.GetEnumerator();
+
+            AssertThrows<Exception>(() => e.MoveNext().Wait(), ex_ => ((AggregateException)ex_).InnerExceptions.Single() is TaskCanceledException);
+        }
+#endif
+
         class MyObservable<T> : IObservable<T>
         {
             private Func<IObserver<T>, IDisposable> _subscribe;