public
Created

An async version of xUnit's Async.Throws. Use it like so: await ThrowsAsync<AuthenticationException>(async () => await obj.GetStuffAsync());

  • Download Gist
ThrowsAsync.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13
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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.