1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System;
- namespace Tests
- {
- internal class AssertEx
- {
- internal static void Throws<T>(Action action)
- where T : Exception
- {
- Throws<T>(action, _ => true);
- }
- internal static void Throws<T>(Action action, Func<T, bool> assert)
- where T : Exception
- {
- var failed = false;
- try
- {
- action();
- }
- catch (T ex)
- {
- Assert.IsTrue(assert(ex));
- failed = true;
- }
- Assert.IsTrue(failed);
- }
- internal static void SucceedOrFailProper(Action action)
- {
- try
- {
- action();
- }
- catch (AggregateException ex)
- {
- var inner = ex.Flatten().InnerException;
- // TODO: proper assert; unfortunately there's not always a good call stack
- }
- }
- }
- }
|