Cast.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 Cast : AsyncEnumerableTests
  11. {
  12. [Fact]
  13. public void Cast_Null()
  14. {
  15. Assert.Throws<ArgumentNullException>(() => AsyncEnumerable.Cast<int>(default));
  16. }
  17. [Fact]
  18. public async Task Cast1()
  19. {
  20. var xs = new object[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  21. var ys = xs.Cast<int>();
  22. var e = ys.GetAsyncEnumerator();
  23. await HasNextAsync(e, 1);
  24. await HasNextAsync(e, 2);
  25. await HasNextAsync(e, 3);
  26. await HasNextAsync(e, 4);
  27. await NoNextAsync(e);
  28. }
  29. [Fact]
  30. public void Cast2()
  31. {
  32. var xs = new[] { new EventArgs(), new EventArgs(), new EventArgs() }.ToAsyncEnumerable();
  33. var ys = xs.Cast<EventArgs>();
  34. Assert.Same(xs, ys);
  35. }
  36. }
  37. }