IgnoreElements.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 IgnoreElements : AsyncEnumerableExTests
  12. {
  13. [Fact]
  14. public void IgnoreElements_Null()
  15. {
  16. AssertThrows<ArgumentNullException>(() => AsyncEnumerableEx.IgnoreElements(default(IAsyncEnumerable<int>)));
  17. }
  18. [Fact]
  19. public void IgnoreElements1()
  20. {
  21. var xs = AsyncEnumerable.Empty<int>().IgnoreElements();
  22. var e = xs.GetAsyncEnumerator();
  23. NoNext(e);
  24. AssertThrows<InvalidOperationException>(() => { var ignored = e.Current; });
  25. }
  26. [Fact]
  27. public void IgnoreElements2()
  28. {
  29. var xs = Return42.IgnoreElements();
  30. var e = xs.GetAsyncEnumerator();
  31. NoNext(e);
  32. AssertThrows<InvalidOperationException>(() => { var ignored = e.Current; });
  33. }
  34. [Fact]
  35. public void IgnoreElements3()
  36. {
  37. var xs = AsyncEnumerable.Range(0, 10).IgnoreElements();
  38. var e = xs.GetAsyncEnumerator();
  39. NoNext(e);
  40. AssertThrows<InvalidOperationException>(() => { var ignored = e.Current; });
  41. }
  42. [Fact]
  43. public void IgnoreElements4()
  44. {
  45. var ex = new Exception("Bang!");
  46. var xs = Throw<int>(ex).IgnoreElements();
  47. var e = xs.GetAsyncEnumerator();
  48. AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
  49. }
  50. [Fact]
  51. public async Task IgnoreElements5()
  52. {
  53. var xs = AsyncEnumerable.Range(0, 10).IgnoreElements();
  54. await SequenceIdentity(xs);
  55. }
  56. }
  57. }