Repeat.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Repeat : AsyncEnumerableTests
  11. {
  12. [Fact]
  13. public void Repeat_Null()
  14. {
  15. Assert.Throws<ArgumentOutOfRangeException>(() => AsyncEnumerable.Repeat(0, -1));
  16. }
  17. [Fact]
  18. public async Task Repeat_Many()
  19. {
  20. var xs = AsyncEnumerable.Repeat(2, 5);
  21. var e = xs.GetAsyncEnumerator();
  22. await HasNextAsync(e, 2);
  23. await HasNextAsync(e, 2);
  24. await HasNextAsync(e, 2);
  25. await HasNextAsync(e, 2);
  26. await HasNextAsync(e, 2);
  27. await NoNextAsync(e);
  28. }
  29. [Fact]
  30. public async Task Repeat_Zero()
  31. {
  32. var xs = AsyncEnumerable.Repeat(2, 0);
  33. var e = xs.GetAsyncEnumerator();
  34. await NoNextAsync(e);
  35. }
  36. [Fact]
  37. public async Task Repeat_Count()
  38. {
  39. var xs = AsyncEnumerable.Repeat(2, 5);
  40. Assert.Equal(5, await xs.CountAsync());
  41. }
  42. [Fact]
  43. public async Task Repeat_ToArray()
  44. {
  45. var xs = AsyncEnumerable.Repeat(2, 5);
  46. Assert.Equal(Enumerable.Repeat(2, 5), await xs.ToArrayAsync());
  47. }
  48. [Fact]
  49. public async Task Repeat_ToList()
  50. {
  51. var xs = AsyncEnumerable.Repeat(2, 5);
  52. Assert.Equal(Enumerable.Repeat(2, 5), await xs.ToListAsync());
  53. }
  54. }
  55. }