1
0

ToList.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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;
  8. using System.Threading.Tasks;
  9. using Xunit;
  10. namespace Tests
  11. {
  12. public class ToList : AsyncEnumerableTests
  13. {
  14. [Fact]
  15. public async Task ToList_Null()
  16. {
  17. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.ToList<int>(default));
  18. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.ToList<int>(default, CancellationToken.None));
  19. }
  20. [Fact]
  21. public void ToList1()
  22. {
  23. var xs = new[] { 42, 25, 39 };
  24. var res = xs.ToAsyncEnumerable().ToList();
  25. Assert.True(res.Result.SequenceEqual(xs));
  26. }
  27. [Fact]
  28. public void ToList2()
  29. {
  30. var xs = AsyncEnumerable.Empty<int>();
  31. var res = xs.ToList();
  32. Assert.True(res.Result.Count == 0);
  33. }
  34. [Fact]
  35. public void ToList3()
  36. {
  37. var ex = new Exception("Bang!");
  38. var res = Throw<int>(ex).ToList();
  39. AssertThrows<Exception>(() => res.Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
  40. }
  41. }
  42. }