|
@@ -3,7 +3,9 @@
|
|
|
// 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 Xunit;
|
|
|
|
|
|
namespace Tests
|
|
@@ -17,25 +19,57 @@ namespace Tests
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void ToEnumerable1()
|
|
|
+ public void ToEnumerable_Single()
|
|
|
{
|
|
|
var xs = Return42.ToEnumerable();
|
|
|
Assert.True(xs.SequenceEqual(new[] { 42 }));
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void ToEnumerable2()
|
|
|
+ public void ToEnumerable_Empty()
|
|
|
{
|
|
|
var xs = AsyncEnumerable.Empty<int>().ToEnumerable();
|
|
|
Assert.True(xs.SequenceEqual(new int[0]));
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void ToEnumerable3()
|
|
|
+ public void ToEnumerable_Throws_Source()
|
|
|
{
|
|
|
var ex = new Exception("Bang");
|
|
|
var xs = Throw<int>(ex).ToEnumerable();
|
|
|
Assert.Throws<Exception>(() => xs.GetEnumerator().MoveNext());
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void ToEnumerable_Many()
|
|
|
+ {
|
|
|
+ var xs = new[] { 1, 2, 3 };
|
|
|
+
|
|
|
+ Assert.Equal(xs, xs.ToAsyncEnumerable().ToEnumerable());
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void ToEnumerable_Many_Yield()
|
|
|
+ {
|
|
|
+ var xs = new[] { 1, 2, 3 };
|
|
|
+
|
|
|
+ Assert.Equal(xs, Yielded(xs).ToEnumerable());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static async IAsyncEnumerable<int> Yielded(IEnumerable<int> xs)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ foreach (var x in xs)
|
|
|
+ {
|
|
|
+ await Task.Yield();
|
|
|
+ yield return x;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ await Task.Yield();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|