Browse Source

Modernize Ix.Async tests.

Bart De Smet 7 years ago
parent
commit
ab166038dd
22 changed files with 117 additions and 112 deletions
  1. 6 6
      Ix.NET/Source/System.Interactive.Async.Tests/AsyncTests.Bugs.cs
  2. 13 16
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/AsyncEnumerableExTests.cs
  3. 14 14
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Buffer.cs
  4. 9 8
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Catch.cs
  5. 6 5
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Concat.cs
  6. 2 1
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Defer.cs
  7. 1 1
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/DistinctUntilChanged.cs
  8. 6 6
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Do.cs
  9. 3 3
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Expand.cs
  10. 2 2
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Finally.cs
  11. 4 4
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Generate.cs
  12. 2 2
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/IgnoreElements.cs
  13. 10 10
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/MaxBy.cs
  14. 10 10
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/MinBy.cs
  15. 5 4
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/OnErrorResumeNext.cs
  16. 4 4
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Repeat.cs
  17. 3 2
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Retry.cs
  18. 2 1
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Return.cs
  19. 4 4
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Scan.cs
  20. 2 1
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/SelectMany.cs
  21. 5 4
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/StartWith.cs
  22. 4 4
      Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Using.cs

+ 6 - 6
Ix.NET/Source/System.Interactive.Async.Tests/AsyncTests.Bugs.cs

@@ -41,9 +41,9 @@ namespace Tests
 
             await disposed.Task;
 
-            Assert.True(disposed.Task.Result);
+            Assert.True(await disposed.Task);
 
-            Assert.False(e.MoveNextAsync().Result);
+            Assert.False(await e.MoveNextAsync());
 
             var next = await e.MoveNextAsync();
             Assert.False(next);
@@ -92,22 +92,22 @@ namespace Tests
         }
 
         [Fact]
-        public void SelectManyDisposeInvokedOnlyOnce()
+        public async Task SelectManyDisposeInvokedOnlyOnceAsync()
         {
             var disposeCounter = new DisposeCounter();
 
-            var result = new[] { 1 }.ToAsyncEnumerable().SelectMany(i => disposeCounter).Select(i => i).ToList().Result;
+            var result = await new[] { 1 }.ToAsyncEnumerable().SelectMany(i => disposeCounter).Select(i => i).ToList();
 
             Assert.Empty(result);
             Assert.Equal(1, disposeCounter.DisposeCount);
         }
 
         [Fact]
-        public void SelectManyInnerDispose()
+        public async Task SelectManyInnerDisposeAsync()
         {
             var disposes = Enumerable.Range(0, 10).Select(_ => new DisposeCounter()).ToList();
 
-            var result = AsyncEnumerable.Range(0, 10).SelectMany(i => disposes[i]).Select(i => i).ToList().Result;
+            var result = await AsyncEnumerable.Range(0, 10).SelectMany(i => disposes[i]).Select(i => i).ToList();
 
             Assert.Empty(result);
             Assert.True(disposes.All(d => d.DisposeCount == 1));

+ 13 - 16
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/AsyncEnumerableExTests.cs

@@ -15,30 +15,28 @@ namespace Tests
     {
         protected static readonly IAsyncEnumerable<int> Return42 = AsyncEnumerableEx.Return(42);
         protected static IAsyncEnumerable<T> Throw<T>(Exception exception) => AsyncEnumerableEx.Throw<T>(exception);
-        protected static Func<Exception, bool> SingleInnerExceptionMatches(Exception ex) => e => ((AggregateException)e).Flatten().InnerExceptions.Single() == ex;
 
-        protected const int WaitTimeoutMs = 5000;
-
-#pragma warning disable xUnit1013 // Public method should be marked as test
-        public void AssertThrows<E>(Action a, Func<E, bool> assert)
-            where E : Exception
+        protected async Task AssertThrowsAsync<TException>(Task t)
+            where TException : Exception
         {
-            var hasFailed = false;
+            await Assert.ThrowsAsync<TException>(() => t);
+        }
 
+        protected async Task AssertThrowsAsync(Task t, Exception e)
+        {
             try
             {
-                a();
+                await t;
             }
-            catch (E e)
+            catch (Exception ex)
             {
-                Assert.True(assert(e));
-                hasFailed = true;
+                Assert.Same(e, ex);
             }
+        }
 
-            if (!hasFailed)
-            {
-                Assert.True(false);
-            }
+        protected Task AssertThrowsAsync<T>(ValueTask<T> t, Exception e)
+        {
+            return AssertThrowsAsync(t.AsTask(), e);
         }
 
         protected async Task NoNextAsync<T>(IAsyncEnumerator<T> e)
@@ -67,6 +65,5 @@ namespace Tests
 
             res1.ShouldAllBeEquivalentTo(res2);
         }
-#pragma warning restore xUnit1013 // Public method should be marked as test
     }
 }

+ 14 - 14
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Buffer.cs

@@ -24,57 +24,57 @@ namespace Tests
         }
 
         [Fact]
-        public void Buffer1()
+        public async Task Buffer1Async()
         {
             var xs = new[] { 1, 2, 3, 4, 5 }.ToAsyncEnumerable().Buffer(2);
 
             var e = xs.GetAsyncEnumerator();
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 1, 2 }));
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 3, 4 }));
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 5 }));
 
-            Assert.False(e.MoveNextAsync().Result);
+            Assert.False(await e.MoveNextAsync());
         }
 
         [Fact]
-        public void Buffer2()
+        public async Task Buffer2Async()
         {
             var xs = new[] { 1, 2, 3, 4, 5 }.ToAsyncEnumerable().Buffer(3, 2);
 
             var e = xs.GetAsyncEnumerator();
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 1, 2, 3 }));
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 3, 4, 5 }));
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 5 }));
 
-            Assert.False(e.MoveNextAsync().Result);
+            Assert.False(await e.MoveNextAsync());
         }
 
         [Fact]
-        public void Buffer3()
+        public async Task Buffer3Async()
         {
             var xs = new[] { 1, 2, 3, 4, 5 }.ToAsyncEnumerable().Buffer(2, 3);
 
             var e = xs.GetAsyncEnumerator();
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 1, 2 }));
 
-            Assert.True(e.MoveNextAsync().Result);
+            Assert.True(await e.MoveNextAsync());
             Assert.True(e.Current.SequenceEqual(new[] { 4, 5 }));
 
-            Assert.False(e.MoveNextAsync().Result);
+            Assert.False(await e.MoveNextAsync());
         }
 
         [Fact]

+ 9 - 8
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Catch.cs

@@ -112,7 +112,7 @@ namespace Tests
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
 
             Assert.False(err);
         }
@@ -133,7 +133,7 @@ namespace Tests
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex2));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex2);
         }
 
         [Fact]
@@ -160,7 +160,7 @@ namespace Tests
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
@@ -224,20 +224,21 @@ namespace Tests
         [Fact]
         public async Task Catch10Async()
         {
-            var res = CatchXss().Catch();
+            var ex = new Exception("Bang!");
+            var res = CatchXss(ex).Catch();
 
             var e = res.GetAsyncEnumerator();
             await HasNextAsync(e, 1);
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single().Message == "Bang!");
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
-        private IEnumerable<IAsyncEnumerable<int>> CatchXss()
+        private IEnumerable<IAsyncEnumerable<int>> CatchXss(Exception ex)
         {
             yield return new[] { 1, 2, 3 }.ToAsyncEnumerable().Concat(Throw<int>(new Exception("!!!")));
-            throw new Exception("Bang!");
+            throw ex;
         }
 
         [Fact]
@@ -257,7 +258,7 @@ namespace Tests
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]

+ 6 - 5
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Concat.cs

@@ -56,13 +56,14 @@ namespace Tests
             await HasNextAsync(e, 3);
             await HasNextAsync(e, 4);
             await HasNextAsync(e, 5);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
         public async Task Concat6Async()
         {
-            var res = AsyncEnumerableEx.Concat(ConcatXss());
+            var ex = new Exception("Bang");
+            var res = AsyncEnumerableEx.Concat(ConcatXss(ex));
 
             var e = res.GetAsyncEnumerator();
             await HasNextAsync(e, 1);
@@ -70,7 +71,7 @@ namespace Tests
             await HasNextAsync(e, 3);
             await HasNextAsync(e, 4);
             await HasNextAsync(e, 5);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single().Message == "Bang!");
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
@@ -85,11 +86,11 @@ namespace Tests
             await SequenceIdentity(res);
         }
 
-        private static IEnumerable<IAsyncEnumerable<int>> ConcatXss()
+        private static IEnumerable<IAsyncEnumerable<int>> ConcatXss(Exception ex)
         {
             yield return new[] { 1, 2, 3 }.ToAsyncEnumerable();
             yield return new[] { 4, 5 }.ToAsyncEnumerable();
-            throw new Exception("Bang!");
+            throw ex;
         }
     }
 }

+ 2 - 1
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Defer.cs

@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace Tests
@@ -18,7 +19,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task Defer1Async()
+        public async Task Defer1Async()
         {
             var x = 0;
             var xs = AsyncEnumerableEx.Defer<int>(() => new[] { x }.ToAsyncEnumerable());

+ 1 - 1
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/DistinctUntilChanged.cs

@@ -68,7 +68,7 @@ namespace Tests
             await HasNextAsync(e, 1);
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]

+ 6 - 6
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Do.cs

@@ -55,14 +55,14 @@ namespace Tests
         }
 
         [Fact]
-        public void Do2()
+        public async Task Do2()
         {
             var ex = new Exception("Bang");
             var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
             var ys = xs.Do(x => { throw ex; });
 
             var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
@@ -112,7 +112,7 @@ namespace Tests
         }
 
         [Fact]
-        public void Do5()
+        public async Task Do5()
         {
             var ex = new Exception("Bang");
             var exa = default(Exception);
@@ -122,7 +122,7 @@ namespace Tests
             var ys = xs.Do(x => { hasv = true; }, exx => { exa = exx; }, () => { done = true; });
 
             var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ex_.InnerException == ex);
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
 
             Assert.False(hasv);
             Assert.False(done);
@@ -130,7 +130,7 @@ namespace Tests
         }
 
         [Fact]
-        public void Do6()
+        public async Task Do6()
         {
             var ex = new Exception("Bang");
             var exa = default(Exception);
@@ -139,7 +139,7 @@ namespace Tests
             var ys = xs.Do(x => { hasv = true; }, exx => { exa = exx; });
 
             var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ex_.InnerException == ex);
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
 
             Assert.False(hasv);
             Assert.Same(exa, ex);

+ 3 - 3
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Expand.cs

@@ -36,13 +36,13 @@ namespace Tests
         }
 
         [Fact]
-        public void Expand2()
+        public async Task Expand2()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 2, 3 }.ToAsyncEnumerable().Expand(new Func<int, IAsyncEnumerable<int>>(x => { throw ex; }));
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
@@ -53,7 +53,7 @@ namespace Tests
             var e = xs.GetAsyncEnumerator();
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is NullReferenceException);
+            await AssertThrowsAsync<NullReferenceException>(e.MoveNextAsync().AsTask());
         }
 
         [Fact]

+ 2 - 2
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Finally.cs

@@ -53,7 +53,7 @@ namespace Tests
         }
 
         [Fact]
-        public void Finally3()
+        public async Task Finally3Async()
         {
             var ex = new Exception("Bang!");
 
@@ -64,7 +64,7 @@ namespace Tests
             var e = xs.GetAsyncEnumerator();
 
             Assert.False(b);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
 
             Assert.True(b);
         }

+ 4 - 4
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Generate.cs

@@ -35,13 +35,13 @@ namespace Tests
         }
 
         [Fact]
-        public void Generate2()
+        public async Task Generate2Async()
         {
             var ex = new Exception("Bang!");
             var xs = AsyncEnumerableEx.Generate(0, x => { throw ex; }, x => x + 1, x => x * x);
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).InnerExceptions.Single() == ex);
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
@@ -52,7 +52,7 @@ namespace Tests
 
             var e = xs.GetAsyncEnumerator();
             await HasNextAsync(e, 0);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).InnerExceptions.Single() == ex);
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
@@ -63,7 +63,7 @@ namespace Tests
 
             var e = xs.GetAsyncEnumerator();
             await HasNextAsync(e, 0);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).InnerExceptions.Single() == ex);
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]

+ 2 - 2
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/IgnoreElements.cs

@@ -46,13 +46,13 @@ namespace Tests
         }
 
         [Fact]
-        public void IgnoreElements4()
+        public async Task IgnoreElements4Async()
         {
             var ex = new Exception("Bang!");
             var xs = Throw<int>(ex).IgnoreElements();
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]

+ 10 - 10
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/MaxBy.cs

@@ -30,47 +30,47 @@ namespace Tests
         }
 
         [Fact]
-        public void MaxBy1()
+        public async Task MaxBy1Async()
         {
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().MaxBy(x => x / 2);
-            var res = xs.Result;
+            var res = await xs;
 
             Assert.True(res.SequenceEqual(new[] { 7, 6 }));
         }
 
         [Fact]
-        public void MaxBy2()
+        public async Task MaxBy2()
         {
             var xs = new int[0].ToAsyncEnumerable().MaxBy(x => x / 2);
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is InvalidOperationException);
+            await AssertThrowsAsync<InvalidOperationException>(xs);
         }
 
         [Fact]
-        public void MaxBy3()
+        public async Task MaxBy3()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().MaxBy(x => { if (x == 3) throw ex; return x; });
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(xs, ex);
         }
 
         [Fact]
-        public void MaxBy4()
+        public async Task MaxBy4()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().MaxBy(x => { if (x == 4) throw ex; return x; });
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(xs, ex);
         }
 
         [Fact]
-        public void MaxBy5()
+        public async Task MaxBy5()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().Concat(Throw<int>(ex)).MaxBy(x => x, Comparer<int>.Default);
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(xs, ex);
         }
     }
 }

+ 10 - 10
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/MinBy.cs

@@ -30,47 +30,47 @@ namespace Tests
         }
 
         [Fact]
-        public void MinBy1()
+        public async Task MinBy1Async()
         {
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().MinBy(x => x / 2);
-            var res = xs.Result;
+            var res = await xs;
 
             Assert.True(res.SequenceEqual(new[] { 3, 2 }));
         }
 
         [Fact]
-        public void MinBy2()
+        public async Task MinBy2Async()
         {
             var xs = new int[0].ToAsyncEnumerable().MinBy(x => x / 2);
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is InvalidOperationException);
+            await AssertThrowsAsync<InvalidOperationException>(xs);
         }
 
         [Fact]
-        public void MinBy3()
+        public async Task MinBy3Async()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().MinBy(x => { if (x == 3) throw ex; return x; });
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(xs, ex);
         }
 
         [Fact]
-        public void MinBy4()
+        public async Task MinBy4Async()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().MinBy(x => { if (x == 4) throw ex; return x; });
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(xs, ex);
         }
 
         [Fact]
-        public void MinBy5()
+        public async Task MinBy5Async()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 3, 5, 7, 6, 4, 2 }.ToAsyncEnumerable().Concat(Throw<int>(ex)).MinBy(x => x, Comparer<int>.Default);
 
-            AssertThrows<Exception>(() => xs.Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(xs, ex);
         }
     }
 }

+ 5 - 4
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/OnErrorResumeNext.cs

@@ -88,20 +88,21 @@ namespace Tests
         [Fact]
         public async Task OnErrorResumeNext10Async()
         {
-            var res = OnErrorResumeNextXss().OnErrorResumeNext();
+            var ex = new Exception("Bang!");
+            var res = OnErrorResumeNextXss(ex).OnErrorResumeNext();
 
             var e = res.GetAsyncEnumerator();
             await HasNextAsync(e, 1);
             await HasNextAsync(e, 2);
             await HasNextAsync(e, 3);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single().Message == "Bang!");
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
-        private IEnumerable<IAsyncEnumerable<int>> OnErrorResumeNextXss()
+        private IEnumerable<IAsyncEnumerable<int>> OnErrorResumeNextXss(Exception ex)
         {
             yield return new[] { 1, 2, 3 }.ToAsyncEnumerable().Concat(Throw<int>(new Exception("!!!")));
-            throw new Exception("Bang!");
+            throw ex;
         }
 
         [Fact]

+ 4 - 4
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Repeat.cs

@@ -115,21 +115,21 @@ namespace Tests
         }
 
         [Fact]
-        public void RepeatSequence6()
+        public async Task RepeatSequence6Async()
         {
             var xs = new FailRepeat().ToAsyncEnumerable().Repeat();
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is NotImplementedException);
+            await AssertThrowsAsync<NotImplementedException>(e.MoveNextAsync().AsTask());
         }
 
         [Fact]
-        public void RepeatSequence7()
+        public async Task RepeatSequence7Async()
         {
             var xs = new FailRepeat().ToAsyncEnumerable().Repeat(3);
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is NotImplementedException);
+            await AssertThrowsAsync<NotImplementedException>(e.MoveNextAsync().AsTask());
         }
 
         private static IEnumerable<int> RepeatXs(Action started)

+ 3 - 2
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Retry.cs

@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace Tests
@@ -21,7 +22,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task Retry1Async()
+        public async Task Retry1Async()
         {
             var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable();
 
@@ -35,7 +36,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task Retry2Async()
+        public async Task Retry2Async()
         {
             var ex = new InvalidOperationException("Bang!");
 

+ 2 - 1
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Return.cs

@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information. 
 
 using System.Linq;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace Tests
@@ -10,7 +11,7 @@ namespace Tests
     public class Return : AsyncEnumerableExTests
     {
         [Fact]
-        public async System.Threading.Tasks.Task Return1Async()
+        public async Task Return1Async()
         {
             var xs = AsyncEnumerableEx.Return(42);
             await HasNextAsync(xs.GetAsyncEnumerator(), 42);

+ 4 - 4
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Scan.cs

@@ -46,23 +46,23 @@ namespace Tests
         }
 
         [Fact]
-        public void Scan3()
+        public async Task Scan3()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan(8, new Func<int, int, int>((x, y) => { throw ex; }));
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]
-        public void Scan4()
+        public async Task Scan4()
         {
             var ex = new Exception("Bang!");
             var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan(new Func<int, int, int>((x, y) => { throw ex; }));
 
             var e = xs.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
 
         [Fact]

+ 2 - 1
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/SelectMany.cs

@@ -4,6 +4,7 @@
 
 using System;
 using System.Linq;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace Tests
@@ -18,7 +19,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task SelectMany1Async()
+        public async Task SelectMany1Async()
         {
             var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
             var ys = new[] { 3, 4 }.ToAsyncEnumerable();

+ 5 - 4
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/StartWith.cs

@@ -4,6 +4,7 @@
 
 using System;
 using System.Linq;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace Tests
@@ -18,7 +19,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task StartWith1Async()
+        public async Task StartWith1Async()
         {
             var xs = AsyncEnumerable.Empty<int>().StartWith(1, 2);
 
@@ -29,7 +30,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task StartWith2Async()
+        public async Task StartWith2Async()
         {
             var xs = Return42.StartWith(40, 41);
 
@@ -41,7 +42,7 @@ namespace Tests
         }
 
         [Fact]
-        public async System.Threading.Tasks.Task StartWith3Async()
+        public async Task StartWith3Async()
         {
             var ex = new Exception("Bang!");
             var xs = Throw<int>(ex).StartWith(1, 2);
@@ -49,7 +50,7 @@ namespace Tests
             var e = xs.GetAsyncEnumerator();
             await HasNextAsync(e, 1);
             await HasNextAsync(e, 2);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
         }
     }
 }

+ 4 - 4
Ix.NET/Source/System.Interactive.Async.Tests/System/Linq/Operators/Using.cs

@@ -128,11 +128,11 @@ namespace Tests
 
             await NoNextAsync(e);
 
-            Assert.True(disposed.Task.Result);
+            Assert.True(await disposed.Task);
         }
 
         [Fact]
-        public void Using5()
+        public async Task Using5Async()
         {
             var ex = new Exception("Bang!");
             var i = 0;
@@ -153,11 +153,11 @@ namespace Tests
 
             Assert.Equal(0, i);
 
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
+            await AssertThrowsAsync(e.MoveNextAsync(), ex);
 
             Assert.Equal(1, i);
 
-            Assert.True(disposed.Task.Result);
+            Assert.True(await disposed.Task);
         }
 
         [Fact]