AsyncTests.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 Xunit;
  6. namespace Tests
  7. {
  8. public partial class AsyncTests
  9. {
  10. private const int WaitTimeoutMs = 5000;
  11. #pragma warning disable xUnit1013 // Public method should be marked as test
  12. public void AssertThrows<E>(Action a)
  13. where E : Exception
  14. {
  15. Assert.Throws<E>(a);
  16. }
  17. public void AssertThrows<E>(Action a, Func<E, bool> assert)
  18. where E : Exception
  19. {
  20. var hasFailed = false;
  21. try
  22. {
  23. a();
  24. }
  25. catch (E e)
  26. {
  27. Assert.True(assert(e));
  28. hasFailed = true;
  29. }
  30. if (!hasFailed)
  31. {
  32. Assert.True(false);
  33. }
  34. }
  35. #pragma warning restore xUnit1013 // Public method should be marked as test
  36. }
  37. }