Empty.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT 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 Empty : AsyncEnumerableTests
  11. {
  12. [Fact]
  13. public async Task Empty_Basics()
  14. {
  15. var xs = AsyncEnumerable.Empty<int>();
  16. await NoNextAsync(xs.GetAsyncEnumerator());
  17. Assert.Equal(0, xs.GetAsyncEnumerator().Current);
  18. }
  19. [Fact]
  20. public async Task Empty_IAsyncPartition()
  21. {
  22. var xs = AsyncEnumerable.Empty<int>();
  23. Assert.Equal(0, await xs.CountAsync());
  24. Assert.Equal(0, await xs.Skip(1).CountAsync());
  25. Assert.Equal(0, await xs.Take(1).CountAsync());
  26. await AssertThrowsAsync<InvalidOperationException>(xs.FirstAsync().AsTask());
  27. await AssertThrowsAsync<InvalidOperationException>(xs.LastAsync().AsTask());
  28. await AssertThrowsAsync<InvalidOperationException>(xs.SingleAsync().AsTask());
  29. Assert.Empty(await xs.ToArrayAsync());
  30. Assert.Empty(await xs.ToListAsync());
  31. }
  32. }
  33. }