Bläddra i källkod

Moving Return to AsyncEnumerableEx.

Bart De Smet 8 år sedan
förälder
incheckning
38c9f3c972

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

@@ -79,9 +79,12 @@ namespace Tests
         [Fact]
         public async Task TakeOneFromSelectMany()
         {
-            var enumerable = AsyncEnumerable
-                .Return(0)
-                .SelectMany(_ => AsyncEnumerable.Return("Check"))
+            var ret0 = new[] { 0 }.ToAsyncEnumerable();
+            var retCheck = new[] { "Check" }.ToAsyncEnumerable();
+
+            var enumerable =
+                ret0
+                .SelectMany(_ => retCheck)
                 .Take(1)
                 .Do(_ => { });
 
@@ -93,7 +96,7 @@ namespace Tests
         {
             var disposeCounter = new DisposeCounter();
 
-            var result = AsyncEnumerable.Return(1).SelectMany(i => disposeCounter).Select(i => i).ToList().Result;
+            var result = new[] { 1 }.ToAsyncEnumerable().SelectMany(i => disposeCounter).Select(i => i).ToList().Result;
 
             Assert.Equal(0, result.Count);
             Assert.Equal(1, disposeCounter.DisposeCount);
@@ -113,7 +116,7 @@ namespace Tests
         [Fact]
         public void DisposeAfterCreation()
         {
-            var enumerable = AsyncEnumerable.Return(0) as IDisposable;
+            var enumerable = new[] { 1 }.ToAsyncEnumerable() as IDisposable;
             enumerable?.Dispose();
         }
 

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

@@ -13,7 +13,7 @@ namespace Tests
 {
     public class AsyncEnumerableExTests
     {
-        protected static readonly IAsyncEnumerable<int> Return42 = AsyncEnumerable.Return(42);
+        protected static readonly IAsyncEnumerable<int> Return42 = AsyncEnumerableEx.Return(42);
         protected static IAsyncEnumerable<T> Throw<T>(Exception exception) => AsyncEnumerable.Throw<T>(exception);
         protected static Func<Exception, bool> SingleInnerExceptionMatches(Exception ex) => e => ((AggregateException)e).Flatten().InnerExceptions.Single() == ex;
 

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

@@ -22,7 +22,7 @@ namespace Tests
         [Fact]
         public void Expand1()
         {
-            var xs = new[] { 2, 3 }.ToAsyncEnumerable().Expand(x => AsyncEnumerable.Return(x - 1).Repeat(x - 1));
+            var xs = new[] { 2, 3 }.ToAsyncEnumerable().Expand(x => AsyncEnumerableEx.Return(x - 1).Repeat(x - 1));
 
             var e = xs.GetAsyncEnumerator();
             HasNext(e, 2);
@@ -59,7 +59,7 @@ namespace Tests
         [Fact]
         public async Task Expand4()
         {
-            var xs = new[] { 2, 3 }.ToAsyncEnumerable().Expand(x => AsyncEnumerable.Return(x - 1).Repeat(x - 1));
+            var xs = new[] { 2, 3 }.ToAsyncEnumerable().Expand(x => AsyncEnumerableEx.Return(x - 1).Repeat(x - 1));
 
             await SequenceIdentity(xs);
         }

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

@@ -7,12 +7,12 @@ using Xunit;
 
 namespace Tests
 {
-    public class Return : AsyncEnumerableTests
+    public class Return : AsyncEnumerableExTests
     {
         [Fact]
         public void Return1()
         {
-            var xs = Return42;
+            var xs = AsyncEnumerableEx.Return(42);
             HasNext(xs.GetAsyncEnumerator(), 42);
         }
     }

+ 16 - 0
Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Return.cs

@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System.Collections.Generic;
+
+namespace System.Linq
+{
+    public static partial class AsyncEnumerableEx
+    {
+        public static IAsyncEnumerable<TValue> Return<TValue>(TValue value)
+        {
+            return new[] { value }.ToAsyncEnumerable();
+        }
+    }
+}

+ 1 - 1
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/AsyncEnumerableTests.cs

@@ -13,7 +13,7 @@ namespace Tests
 {
     public class AsyncEnumerableTests
     {
-        protected static readonly IAsyncEnumerable<int> Return42 = AsyncEnumerable.Return(42);
+        protected static readonly IAsyncEnumerable<int> Return42 = new[] { 42 }.ToAsyncEnumerable();
         protected static IAsyncEnumerable<T> Throw<T>(Exception exception) => AsyncEnumerable.Throw<T>(exception);
         protected static Func<Exception, bool> SingleInnerExceptionMatches(Exception ex) => e => ((AggregateException)e).Flatten().InnerExceptions.Single() == ex;
 

+ 0 - 5
Ix.NET/Source/System.Linq.Async/System/Linq/AsyncEnumerable.cs

@@ -17,11 +17,6 @@ namespace System.Linq
             return source.Select(x => x);
         }
 
-        public static IAsyncEnumerable<TValue> Return<TValue>(TValue value)
-        {
-            return new[] { value }.ToAsyncEnumerable();
-        }
-
         public static IAsyncEnumerable<TValue> Throw<TValue>(Exception exception)
         {
             if (exception == null)