Cast.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 Xunit;
  7. namespace Tests
  8. {
  9. public class Cast : AsyncEnumerableTests
  10. {
  11. [Fact]
  12. public void Cast_Null()
  13. {
  14. AssertThrows<ArgumentNullException>(() => AsyncEnumerable.Cast<int>(null));
  15. }
  16. [Fact]
  17. public void Cast1()
  18. {
  19. var xs = new object[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  20. var ys = xs.Cast<int>();
  21. var e = ys.GetAsyncEnumerator();
  22. HasNext(e, 1);
  23. HasNext(e, 2);
  24. HasNext(e, 3);
  25. HasNext(e, 4);
  26. NoNext(e);
  27. }
  28. [Fact]
  29. public void Cast2()
  30. {
  31. var xs = new[] { new EventArgs(), new EventArgs(), new EventArgs() }.ToAsyncEnumerable();
  32. var ys = xs.Cast<EventArgs>();
  33. Assert.Same(xs, ys);
  34. }
  35. }
  36. }