Skip to content

Instantly share code, notes, and snippets.

@haacked
Created January 24, 2013 00:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save haacked/4616032 to your computer and use it in GitHub Desktop.
Save haacked/4616032 to your computer and use it in GitHub Desktop.
Example usage of an async lambda.
Assert.Throws<SomeException>(async () => await obj.GetAsync());
@shiftkey
Copy link

Just pushed AssertEx up to NuGet. Here's a teaser:

If you want to inspect the Task:

public class Subject
{
    public Task GetAsync()
    {
        return Task.Run(() => { throw new SomeException(); });
    }
}

...

AssertEx.TaskThrows<SomeException>(obj.GetAsync);

@shiftkey
Copy link

I need to write up a decent wiki on how to test async code - all the horrors are coming back to me now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment