AsyncTests.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #if !NO_TPL
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using Xunit;
  9. namespace Tests
  10. {
  11. public partial class AsyncTests
  12. {
  13. public void AssertThrows<E>(Action a)
  14. where E : Exception
  15. {
  16. Assert.Throws<E>(a);
  17. }
  18. public void AssertThrows<E>(Action a, Func<E, bool> assert)
  19. where E : Exception
  20. {
  21. var hasFailed = false;
  22. try
  23. {
  24. a();
  25. }
  26. catch (E e)
  27. {
  28. Assert.True(assert(e));
  29. hasFailed = true;
  30. }
  31. if (!hasFailed)
  32. {
  33. Assert.True(false);
  34. }
  35. }
  36. public void NoNext<T>(IAsyncEnumerator<T> e)
  37. {
  38. Assert.False(e.MoveNext().Result);
  39. }
  40. public void HasNext<T>(IAsyncEnumerator<T> e, T value)
  41. {
  42. Assert.True(e.MoveNext().Result);
  43. Assert.Equal(value, e.Current);
  44. }
  45. }
  46. }
  47. #endif