AsyncTests.Single.cs 1.6 KB

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