Created
January 24, 2013 00:37
-
-
Save haacked/4616366 to your computer and use it in GitHub Desktop.
An async version of xUnit's Async.Throws. Use it like so: await ThrowsAsync<AuthenticationException>(async () => await obj.GetStuffAsync());
This file contains hidden or 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 async static Task<T> ThrowsAsync<T>(Func<Task> testCode) where T : Exception | |
{ | |
try | |
{ | |
await testCode(); | |
Assert.Throws<T>(() => { }); // Use xUnit's default behavior. | |
} | |
catch (T exception) | |
{ | |
return exception; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment