1
0

AssertEx.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using Xunit;
  3. using System;
  4. namespace Tests
  5. {
  6. internal class AssertEx
  7. {
  8. internal static void Throws<T>(Action action)
  9. where T : Exception
  10. {
  11. Throws<T>(action, _ => true);
  12. }
  13. internal static void Throws<T>(Action action, Func<T, bool> assert)
  14. where T : Exception
  15. {
  16. var failed = false;
  17. try
  18. {
  19. action();
  20. }
  21. catch (T ex)
  22. {
  23. Assert.True(assert(ex));
  24. failed = true;
  25. }
  26. Assert.True(failed);
  27. }
  28. internal static void SucceedOrFailProper(Action action)
  29. {
  30. try
  31. {
  32. action();
  33. }
  34. catch (AggregateException ex)
  35. {
  36. var inner = ex.Flatten().InnerException;
  37. // TODO: proper assert; unfortunately there's not always a good call stack
  38. }
  39. }
  40. }
  41. }