Skip to content

Instantly share code, notes, and snippets.

@bugthesystem
Last active December 14, 2015 00:08
Show Gist options
  • Save bugthesystem/4996444 to your computer and use it in GitHub Desktop.
Save bugthesystem/4996444 to your computer and use it in GitHub Desktop.
Assert helper method for async throw exceptions
public static class AssertExtensions
{
public static async Task ThrowsAsync<TException>(Func<Task> func) where TException : Exception
{
var expected = typeof(TException);
Type actual = null;
try
{
await func();
}
catch (TException exception)
{
actual = exception.GetType();
}
Assert.AreEqual(expected, actual);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment