Skip.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 class Skip : AsyncEnumerableTests
  12. {
  13. [Fact]
  14. public void Skip_Null()
  15. {
  16. AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Skip<int>(default, 5));
  17. }
  18. //[Fact]
  19. //public void Skip0()
  20. //{
  21. // var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  22. // var ys = xs.Skip(-2);
  23. // var e = ys.GetEnumerator();
  24. // NoNext(e);
  25. //}
  26. [Fact]
  27. public void Skip1()
  28. {
  29. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  30. var ys = xs.Skip(2);
  31. var e = ys.GetAsyncEnumerator();
  32. HasNext(e, 3);
  33. HasNext(e, 4);
  34. NoNext(e);
  35. }
  36. [Fact]
  37. public void Skip2()
  38. {
  39. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  40. var ys = xs.Skip(10);
  41. var e = ys.GetAsyncEnumerator();
  42. NoNext(e);
  43. }
  44. [Fact]
  45. public void Skip3()
  46. {
  47. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  48. var ys = xs.Skip(0);
  49. var e = ys.GetAsyncEnumerator();
  50. HasNext(e, 1);
  51. HasNext(e, 2);
  52. HasNext(e, 3);
  53. HasNext(e, 4);
  54. NoNext(e);
  55. }
  56. [Fact]
  57. public void Skip4()
  58. {
  59. var ex = new Exception("Bang");
  60. var xs = Throw<int>(ex);
  61. var ys = xs.Skip(2);
  62. var e = ys.GetAsyncEnumerator();
  63. AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
  64. }
  65. [Fact]
  66. public async Task Skip5()
  67. {
  68. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  69. var ys = xs.Skip(2);
  70. await SequenceIdentity(ys);
  71. }
  72. }
  73. }