AssertEx.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Xunit;
  5. using System;
  6. namespace Tests
  7. {
  8. internal class AssertEx
  9. {
  10. internal static void Throws<T>(Action action, Func<T, bool> assert)
  11. where T : Exception
  12. {
  13. var failed = false;
  14. try
  15. {
  16. action();
  17. }
  18. catch (T ex)
  19. {
  20. Assert.True(assert(ex));
  21. failed = true;
  22. }
  23. Assert.True(failed);
  24. }
  25. internal static void SucceedOrFailProper(Action action)
  26. {
  27. try
  28. {
  29. action();
  30. }
  31. catch (AggregateException ex)
  32. {
  33. var inner = ex.Flatten().InnerException;
  34. // TODO: proper assert; unfortunately there's not always a good call stack
  35. }
  36. }
  37. }
  38. }