StartWith.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Xunit;
  8. namespace Tests
  9. {
  10. public class StartWith : AsyncEnumerableExTests
  11. {
  12. [Fact]
  13. public void StartWith_Null()
  14. {
  15. AssertThrows<ArgumentNullException>(() => AsyncEnumerableEx.StartWith(default, new[] { 1 }));
  16. AssertThrows<ArgumentNullException>(() => AsyncEnumerableEx.StartWith(Return42, default));
  17. }
  18. [Fact]
  19. public void StartWith1()
  20. {
  21. var xs = AsyncEnumerable.Empty<int>().StartWith(1, 2);
  22. var e = xs.GetAsyncEnumerator();
  23. HasNext(e, 1);
  24. HasNext(e, 2);
  25. NoNext(e);
  26. }
  27. [Fact]
  28. public void StartWith2()
  29. {
  30. var xs = Return42.StartWith(40, 41);
  31. var e = xs.GetAsyncEnumerator();
  32. HasNext(e, 40);
  33. HasNext(e, 41);
  34. HasNext(e, 42);
  35. NoNext(e);
  36. }
  37. [Fact]
  38. public void StartWith3()
  39. {
  40. var ex = new Exception("Bang!");
  41. var xs = Throw<int>(ex).StartWith(1, 2);
  42. var e = xs.GetAsyncEnumerator();
  43. HasNext(e, 1);
  44. HasNext(e, 2);
  45. AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), SingleInnerExceptionMatches(ex));
  46. }
  47. }
  48. }