AssertEx.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. [Obsolete("Switch over to xUnit asserts wherever possible")]
  7. internal class AssertEx
  8. {
  9. internal static void Throws<T>(Action action)
  10. where T : Exception
  11. {
  12. Throws<T>(action, _ => true);
  13. }
  14. internal static void Throws<T>(Action action, Func<T, bool> assert)
  15. where T : Exception
  16. {
  17. var failed = false;
  18. try
  19. {
  20. action();
  21. }
  22. catch (T ex)
  23. {
  24. Assert.True(assert(ex));
  25. failed = true;
  26. }
  27. Assert.True(failed);
  28. }
  29. internal static void SucceedOrFailProper(Action action)
  30. {
  31. try
  32. {
  33. action();
  34. }
  35. catch (AggregateException ex)
  36. {
  37. var inner = ex.Flatten().InnerException;
  38. // TODO: proper assert; unfortunately there's not always a good call stack
  39. }
  40. }
  41. }
  42. }