Bläddra i källkod

Initial restructuring of test projects.

Bart De Smet 8 år sedan
förälder
incheckning
705d26d529

+ 0 - 205
Ix.NET/Source/System.Interactive.Async.Tests/AsyncTests.Single.cs

@@ -22,92 +22,6 @@ namespace Tests
             Assert.ThrowsAsync<ArgumentNullException>(() => en.MoveNextAsync());
         }
 
-        [Fact]
-        public void Select_Null()
-        {
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(null, x => x));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(null, (x, i) => x));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(AsyncEnumerable.Return<int>(42), default(Func<int, int>)));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(AsyncEnumerable.Return<int>(42), default(Func<int, int, int>)));
-        }
-
-        [Fact]
-        public void Select1()
-        {
-            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
-            var ys = xs.Select(x => (char)('a' + x));
-
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 'a');
-            HasNext(e, 'b');
-            HasNext(e, 'c');
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Select2()
-        {
-            var xs = new[] { 8, 5, 7 }.ToAsyncEnumerable();
-            var ys = xs.Select((x, i) => (char)('a' + i));
-
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 'a');
-            HasNext(e, 'b');
-            HasNext(e, 'c');
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Select3()
-        {
-            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
-            var ys = xs.Select(x => 1 / x);
-
-            var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is DivideByZeroException);
-        }
-
-        [Fact]
-        public void Select4()
-        {
-            var xs = new[] { 8, 5, 7 }.ToAsyncEnumerable();
-            var ys = xs.Select((x, i) => 1 / i);
-
-            var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is DivideByZeroException);
-        }
-
-        [Fact]
-        public void Select5()
-        {
-            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
-            var ys = xs.Select(i => i + 3).Select(x => (char)('a' + x));
-
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 'd');
-            HasNext(e, 'e');
-            HasNext(e, 'f');
-            NoNext(e);
-        }
-
-        [Fact]
-        public async Task Select7()
-        {
-            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
-            var ys = xs.Select(x => (char)('a' + x));
-
-            await SequenceIdentity(ys);
-        }
-
-        [Fact]
-        public async Task Select8()
-        {
-            var xs = new[] { 8, 5, 7 }.ToAsyncEnumerable();
-            var ys = xs.Select((x, i) => (char)('a' + i));
-
-            await SequenceIdentity(ys);
-        }
-
         [Fact]
         public void SelectWhere2()
         {
@@ -145,125 +59,6 @@ namespace Tests
             NoNext(e);
         }
 
-        [Fact]
-        public void Where_Null()
-        {
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(null, x => true));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(null, (x, i) => true));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(AsyncEnumerable.Return<int>(42), default(Func<int, bool>)));
-            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(AsyncEnumerable.Return<int>(42), default(Func<int, int, bool>)));
-        }
-
-        [Fact]
-        public void Where1()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ys = xs.Where(x => x % 2 == 0);
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 8);
-            HasNext(e, 4);
-            HasNext(e, 6);
-            HasNext(e, 2);
-            HasNext(e, 0);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Where2()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ys = xs.Where((x, i) => i % 2 == 0);
-
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 8);
-            HasNext(e, 7);
-            HasNext(e, 6);
-            HasNext(e, 2);
-            HasNext(e, 0);
-            NoNext(e);
-        }
-
-        [Fact]
-        public void Where3()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ex = new Exception("Bang");
-            var ys = xs.Where(x => { if (x == 4) throw ex; return true; });
-
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 8);
-            HasNext(e, 5);
-            HasNext(e, 7);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
-        }
-
-        [Fact]
-        public void Where4()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ex = new Exception("Bang");
-            var ys = xs.Where((x, i) => { if (i == 3) throw ex; return true; });
-
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 8);
-            HasNext(e, 5);
-            HasNext(e, 7);
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
-        }
-
-        [Fact]
-        public void Where5()
-        {
-            var ex = new Exception("Bang");
-            var xs = AsyncEnumerable.Throw<int>(ex);
-            var ys = xs.Where(x => true);
-
-            var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
-        }
-
-        [Fact]
-        public void Where6()
-        {
-            var ex = new Exception("Bang");
-            var xs = AsyncEnumerable.Throw<int>(ex);
-
-            var ys = xs.Where((x, i) => true);
-            var e = ys.GetAsyncEnumerator();
-            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
-        }
-
-
-        [Fact]
-        public void Where7()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ys = xs.Where(x => x % 2 == 0).Where(x => x > 5);
-            var e = ys.GetAsyncEnumerator();
-            HasNext(e, 8);
-            HasNext(e, 6);
-            NoNext(e);
-        }
-
-        [Fact]
-        public async Task Where8()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ys = xs.Where(x => x % 2 == 0);
-
-            await SequenceIdentity(ys);
-        }
-
-        [Fact]
-        public async Task Where9()
-        {
-            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
-            var ys = xs.Where((x, i) => i % 2 == 0);
-
-            await SequenceIdentity(ys);
-        }
-
-
         [Fact]
         public void SelectMany_Null()
         {

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

@@ -0,0 +1,88 @@
+// 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;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using FluentAssertions;
+using Xunit;
+
+namespace Tests
+{
+    public class AsyncEnumerableTests
+    {
+        protected const int WaitTimeoutMs = 5000;
+
+#pragma warning disable xUnit1013 // Public method should be marked as test
+        public void AssertThrows<E>(Action a)
+            where E : Exception
+        {
+            Assert.Throws<E>(a);
+        }
+
+        [Obsolete("Don't use this, use Assert.ThrowsAsync and await it", true)]
+        public Task AssertThrows<E>(Func<Task> func)
+            where E : Exception
+        {
+            return Assert.ThrowsAsync<E>(func);
+        }
+
+        public void AssertThrows<E>(Action a, Func<E, bool> assert)
+            where E : Exception
+        {
+
+            var hasFailed = false;
+
+            try
+            {
+                a();
+            }
+            catch (E e)
+            {
+                Assert.True(assert(e));
+                hasFailed = true;
+            }
+
+            if (!hasFailed)
+            {
+                Assert.True(false);
+            }
+        }
+
+        public void NoNext<T>(IAsyncEnumerator<T> e)
+        {
+            Assert.False(e.MoveNextAsync().Result);
+        }
+
+        public void HasNext<T>(IAsyncEnumerator<T> e, T value)
+        {
+            Assert.True(e.MoveNextAsync().Result);
+            Assert.Equal(value, e.Current);
+        }
+
+        public async Task SequenceIdentity<T>(IAsyncEnumerable<T> enumerable)
+        {
+            var en1 = enumerable.GetAsyncEnumerator();
+            var en2 = enumerable.GetAsyncEnumerator();
+
+            Assert.Equal(en1.GetType(), en2.GetType());
+
+            await en1.DisposeAsync();
+            await en2.DisposeAsync();
+
+            var e1t = enumerable.ToList();
+            var e2t = enumerable.ToList();
+
+            await Task.WhenAll(e1t, e2t);
+
+
+            var e1Result = e1t.Result;
+            var e2Result = e2t.Result;
+
+            e1Result.ShouldAllBeEquivalentTo(e2Result);
+        }
+#pragma warning restore xUnit1013 // Public method should be marked as test
+    }
+}

+ 100 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Select.cs

@@ -0,0 +1,100 @@
+// 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;
+using System.Linq;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Tests
+{
+    public class Select : AsyncEnumerableTests
+    {
+        [Fact]
+        public void Select_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(null, x => x));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(null, (x, i) => x));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(AsyncEnumerable.Return<int>(42), default(Func<int, int>)));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Select<int, int>(AsyncEnumerable.Return<int>(42), default(Func<int, int, int>)));
+        }
+
+        [Fact]
+        public void Select1()
+        {
+            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
+            var ys = xs.Select(x => (char)('a' + x));
+
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 'a');
+            HasNext(e, 'b');
+            HasNext(e, 'c');
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Select2()
+        {
+            var xs = new[] { 8, 5, 7 }.ToAsyncEnumerable();
+            var ys = xs.Select((x, i) => (char)('a' + i));
+
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 'a');
+            HasNext(e, 'b');
+            HasNext(e, 'c');
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Select3()
+        {
+            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
+            var ys = xs.Select(x => 1 / x);
+
+            var e = ys.GetAsyncEnumerator();
+            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is DivideByZeroException);
+        }
+
+        [Fact]
+        public void Select4()
+        {
+            var xs = new[] { 8, 5, 7 }.ToAsyncEnumerable();
+            var ys = xs.Select((x, i) => 1 / i);
+
+            var e = ys.GetAsyncEnumerator();
+            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() is DivideByZeroException);
+        }
+
+        [Fact]
+        public void Select5()
+        {
+            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
+            var ys = xs.Select(i => i + 3).Select(x => (char)('a' + x));
+
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 'd');
+            HasNext(e, 'e');
+            HasNext(e, 'f');
+            NoNext(e);
+        }
+
+        [Fact]
+        public async Task Select7()
+        {
+            var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
+            var ys = xs.Select(x => (char)('a' + x));
+
+            await SequenceIdentity(ys);
+        }
+
+        [Fact]
+        public async Task Select8()
+        {
+            var xs = new[] { 8, 5, 7 }.ToAsyncEnumerable();
+            var ys = xs.Select((x, i) => (char)('a' + i));
+
+            await SequenceIdentity(ys);
+        }
+    }
+}

+ 132 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Where.cs

@@ -0,0 +1,132 @@
+// 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;
+using System.Linq;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Tests
+{
+    public class Where : AsyncEnumerableTests
+    {
+        [Fact]
+        public void Where_Null()
+        {
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(null, x => true));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(null, (x, i) => true));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(AsyncEnumerable.Return<int>(42), default(Func<int, bool>)));
+            AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Where<int>(AsyncEnumerable.Return<int>(42), default(Func<int, int, bool>)));
+        }
+
+        [Fact]
+        public void Where1()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ys = xs.Where(x => x % 2 == 0);
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 8);
+            HasNext(e, 4);
+            HasNext(e, 6);
+            HasNext(e, 2);
+            HasNext(e, 0);
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Where2()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ys = xs.Where((x, i) => i % 2 == 0);
+
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 8);
+            HasNext(e, 7);
+            HasNext(e, 6);
+            HasNext(e, 2);
+            HasNext(e, 0);
+            NoNext(e);
+        }
+
+        [Fact]
+        public void Where3()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ex = new Exception("Bang");
+            var ys = xs.Where(x => { if (x == 4) throw ex; return true; });
+
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 8);
+            HasNext(e, 5);
+            HasNext(e, 7);
+            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
+        }
+
+        [Fact]
+        public void Where4()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ex = new Exception("Bang");
+            var ys = xs.Where((x, i) => { if (i == 3) throw ex; return true; });
+
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 8);
+            HasNext(e, 5);
+            HasNext(e, 7);
+            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
+        }
+
+        [Fact]
+        public void Where5()
+        {
+            var ex = new Exception("Bang");
+            var xs = AsyncEnumerable.Throw<int>(ex);
+            var ys = xs.Where(x => true);
+
+            var e = ys.GetAsyncEnumerator();
+            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
+        }
+
+        [Fact]
+        public void Where6()
+        {
+            var ex = new Exception("Bang");
+            var xs = AsyncEnumerable.Throw<int>(ex);
+
+            var ys = xs.Where((x, i) => true);
+            var e = ys.GetAsyncEnumerator();
+            AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
+        }
+
+
+        [Fact]
+        public void Where7()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ys = xs.Where(x => x % 2 == 0).Where(x => x > 5);
+            var e = ys.GetAsyncEnumerator();
+            HasNext(e, 8);
+            HasNext(e, 6);
+            NoNext(e);
+        }
+
+        [Fact]
+        public async Task Where8()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ys = xs.Where(x => x % 2 == 0);
+
+            await SequenceIdentity(ys);
+        }
+
+        [Fact]
+        public async Task Where9()
+        {
+            var xs = new[] { 8, 5, 7, 4, 6, 9, 2, 1, 0 }.ToAsyncEnumerable();
+            var ys = xs.Where((x, i) => i % 2 == 0);
+
+            await SequenceIdentity(ys);
+        }
+    }
+}