Cast.cs 1.2 KB

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