The following asynchronous xUnit.net test with a lambda marked with the async modifier fails by reporting that no exception was thrown
If you also need to return the exception to verify it then this might be useful:
public static async Task AssertThrowsAsync(Func func)
{
var expected = typeof (TException);
Exception exception = null;
Type actual = null;
try
{
await func();
}
catch (Exception e)
{
actual = e.GetType();
exception = e;
}
Assert.NotNull(exception);
Assert.Equal(expected, actual);
return exception;
}