AsyncTests.Single.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.Collections.Generic;
  6. using System.Linq;
  7. using Xunit;
  8. namespace Tests
  9. {
  10. public partial class AsyncTests
  11. {
  12. [Fact]
  13. public void MoveNextExtension_Null()
  14. {
  15. var en = default(IAsyncEnumerator<int>);
  16. Assert.ThrowsAsync<ArgumentNullException>(() => en.MoveNextAsync());
  17. }
  18. [Fact]
  19. public void SelectWhere2()
  20. {
  21. var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
  22. var ys = xs.Select(i => i + 2).Where(i => i % 2 == 0);
  23. var e = ys.GetAsyncEnumerator();
  24. HasNext(e, 2);
  25. HasNext(e, 4);
  26. NoNext(e);
  27. }
  28. [Fact]
  29. public void WhereSelect2()
  30. {
  31. var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
  32. var ys = xs.Where(i => i % 2 == 0).Select(i => i + 2);
  33. var e = ys.GetAsyncEnumerator();
  34. HasNext(e, 2);
  35. HasNext(e, 4);
  36. NoNext(e);
  37. }
  38. [Fact]
  39. public void WhereSelect3()
  40. {
  41. var xs = new[] { 0, 1, 2 }.ToAsyncEnumerable();
  42. var ys = xs.Where(i => i % 2 == 0).Select(i => i + 2).Select(i => i + 2);
  43. var e = ys.GetAsyncEnumerator();
  44. HasNext(e, 4);
  45. HasNext(e, 6);
  46. NoNext(e);
  47. }
  48. }
  49. }