ToEnumerable.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Linq;
  6. using Xunit;
  7. namespace Tests
  8. {
  9. public class ToEnumerable : AsyncEnumerableTests
  10. {
  11. [Fact]
  12. public void ToEnumerable_Null()
  13. {
  14. AssertThrows<ArgumentNullException>(() => AsyncEnumerable.ToEnumerable<int>(null));
  15. }
  16. [Fact]
  17. public void ToEnumerable1()
  18. {
  19. var xs = Return42.ToEnumerable();
  20. Assert.True(xs.SequenceEqual(new[] { 42 }));
  21. }
  22. [Fact]
  23. public void ToEnumerable2()
  24. {
  25. var xs = AsyncEnumerable.Empty<int>().ToEnumerable();
  26. Assert.True(xs.SequenceEqual(new int[0]));
  27. }
  28. [Fact]
  29. public void ToEnumerable3()
  30. {
  31. var ex = new Exception("Bang");
  32. var xs = Throw<int>(ex).ToEnumerable();
  33. Assert.Throws<Exception>(() => xs.GetEnumerator().MoveNext());
  34. }
  35. }
  36. }