AsyncTests.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if !NO_TPL
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Xunit;
  7. namespace Tests
  8. {
  9. public partial class AsyncTests
  10. {
  11. public void AssertThrows<E>(Action a)
  12. where E : Exception
  13. {
  14. Assert.Throws<E>(a);
  15. }
  16. public void AssertThrows<E>(Action a, Func<E, bool> assert)
  17. where E : Exception
  18. {
  19. var hasFailed = false;
  20. try
  21. {
  22. a();
  23. }
  24. catch (E e)
  25. {
  26. Assert.True(assert(e));
  27. hasFailed = true;
  28. }
  29. if (!hasFailed)
  30. {
  31. Assert.True(false);
  32. }
  33. }
  34. public void NoNext<T>(IAsyncEnumerator<T> e)
  35. {
  36. Assert.False(e.MoveNext().Result);
  37. }
  38. public void HasNext<T>(IAsyncEnumerator<T> e, T value)
  39. {
  40. Assert.True(e.MoveNext().Result);
  41. Assert.Equal(value, e.Current);
  42. }
  43. }
  44. }
  45. #endif