AsyncTests.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #pragma warning disable xUnit1013 // Public method should be marked as test
  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. #pragma warning restore xUnit1013 // Public method should be marked as test
  35. }
  36. }