最佳答案
So I have a test like the following:
[Fact]
public void Test1()
{
Assert.ThrowsAsync<ArgumentNullException>(() => MethodThatThrows());
}
private async Task MethodThatThrows()
{
await Task.Delay(100);
throw new NotImplementedException();
}
To my surprise, Test1 passes successfully. To make it fail I have to write like this:
Assert.Throws<ArgumentNullException>(() => MethodThatThrows().Wait());
What is the purpose of ThrowsAsync()
, if it does not work in the scenario above?