Oren Novotny 9 år sedan
förälder
incheckning
183c269419

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/ForEach.cs

@@ -19,8 +19,7 @@ namespace System.Linq
             if (action == null)
                 throw new ArgumentNullException(nameof(action));
 
-            source.ForEachAsync(action)
-                  .Wait();
+            source.ForEach(action, CancellationToken.None);
         }
 
         public static void ForEach<TSource>(this IAsyncEnumerable<TSource> source, Action<TSource, int> action)
@@ -30,8 +29,7 @@ namespace System.Linq
             if (action == null)
                 throw new ArgumentNullException(nameof(action));
 
-            source.ForEachAsync(action)
-                  .Wait();
+            source.ForEach(action, CancellationToken.None);
         }
 
 

+ 21 - 0
Ix.NET/Source/Tests/AsyncTests.Aggregates.cs

@@ -929,6 +929,15 @@ namespace Tests
             AssertThrows<Exception>(() => res.Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
         }
 
+        [Fact]
+        public async Task ElementAt7()
+        {
+            var en = new CancellationTestAsyncEnumerable();
+
+            var res = en.ElementAt(1);
+            Assert.Equal(1, await res);
+        }
+
         [Fact]
         public async Task ElementAtOrDefault_Null()
         {
@@ -1053,6 +1062,18 @@ namespace Tests
             Assert.True(ex.SequenceEqual(xs));
         }
 
+        [Fact]
+        public async Task ToArray5()
+        {
+            var res = new[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
+            var xs = new HashSet<int>(res);
+
+            var arr = await xs.ToAsyncEnumerable().ToArray();
+            
+
+            Assert.True(res.SequenceEqual(arr));
+        }
+
         [Fact]
         public async Task ToDictionary_Null()
         {

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

@@ -20,6 +20,7 @@ namespace Tests
         {
             AssertThrows<ArgumentNullException>(() => AsyncEnumerable.ToAsyncEnumerable<int>(default(IEnumerable<int>)));
             AssertThrows<ArgumentNullException>(() => AsyncEnumerable.ToAsyncEnumerable<int>(default(IObservable<int>)));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.ToAsyncEnumerable<int>(default(Task<int>)));
         }
 
         [Fact]

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

@@ -1254,6 +1254,64 @@ namespace Tests
             AssertThrows<Exception>(() => e.MoveNext().Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
         }
 
+        [Fact]
+        public async Task DefaultIfEmpty9()
+        {
+            var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);
+
+            var res = new[] { 42 };
+
+            Assert.True(res.SequenceEqual(await xs.ToArray()));
+        }
+
+        [Fact]
+        public async Task DefaultIfEmpty10()
+        {
+            var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);
+
+            var res = new List<int> { 42 };
+
+            Assert.True(res.SequenceEqual(await xs.ToList()));
+        }
+
+        [Fact]
+        public async Task DefaultIfEmpty11()
+        {
+            var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);
+            
+            Assert.Equal(1, await xs.Count());
+        }
+
+
+        [Fact]
+        public async Task DefaultIfEmpty12()
+        {
+            var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);
+
+            var res = new[] { 1, 2, 3, 4 };
+
+            Assert.True(res.SequenceEqual(await xs.ToArray()));
+        }
+
+        [Fact]
+        public async Task DefaultIfEmpty13()
+        {
+            var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);
+
+            var res = new List<int> { 1, 2, 3, 4 };
+
+            Assert.True(res.SequenceEqual(await xs.ToList()));
+        }
+
+        [Fact]
+        public async Task DefaultIfEmpty14()
+        {
+            var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);
+
+            Assert.Equal(4, await xs.Count());
+        }
+
+
         [Fact]
         public void Distinct_Null()
         {
@@ -1290,6 +1348,32 @@ namespace Tests
             NoNext(e);
         }
 
+        [Fact]
+        public async Task Distinct3()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+            
+            var res = new [] { 1, 2, 3, 5, 4 };
+            Assert.True(res.SequenceEqual(await xs.ToArray()));
+        }
+
+        [Fact]
+        public async Task Distinct4()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+
+            var res = new List<int> { 1, 2, 3, 5, 4 };
+            Assert.True(res.SequenceEqual(await xs.ToList()));
+        }
+
+        [Fact]
+        public async Task Distinct5()
+        {
+            var xs = new[] { 1, 2, 1, 3, 5, 2, 1, 4 }.ToAsyncEnumerable().Distinct();
+            
+            Assert.Equal(5, await xs.Count());
+        }
+
         [Fact]
         public void Reverse_Null()
         {