Skip to content

Instantly share code, notes, and snippets.

@haacked
Created January 24, 2013 00:37

Revisions

  1. haacked created this gist Jan 24, 2013.
    13 changes: 13 additions & 0 deletions ThrowsAsync.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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;
    }