Skip.cs 2.2 KB

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