Last active
January 15, 2016 16:21
-
-
Save JohnLudlow/83b4887be35762f7a12e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class AssertEx | |
{ | |
public static void Throws<T>(Action action) where T : Exception | |
{ | |
Exception actual = null; | |
try | |
{ | |
action(); | |
} | |
catch (T ex) | |
{ | |
actual = ex; | |
} | |
Assert.IsInstanceOfType(actual, typeof(T)); | |
} | |
public static void Throws<T>(Action action, Action<T> assertion) where T : Exception | |
{ | |
Exception actual = null; | |
try | |
{ | |
action(); | |
} | |
catch (T ex) | |
{ | |
actual = ex; | |
} | |
Assert.IsInstanceOfType(actual, typeof(T)); | |
assertion((T)actual); | |
} | |
public static void Throws<T>(Action action, Func<T, bool> assertion) where T : Exception | |
{ | |
Exception actual = null; | |
try | |
{ | |
action(); | |
} | |
catch (T ex) | |
{ | |
actual = ex; | |
} | |
Assert.IsInstanceOfType(actual, typeof(T)); | |
Assert.IsTrue(assertion((T)actual)); | |
} | |
public static T Exception<T>(Action action) where T : Exception | |
{ | |
T actual = null; | |
try | |
{ | |
action(); | |
} | |
catch (T ex) | |
{ | |
actual = ex; | |
} | |
return actual; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment