The following asynchronous xUnit.net test with a lambda marked with the async modifier fails by reporting that no exception was thrown:
[Theory, AutoWebData] public async Task SearchWithNullQueryThrows( SearchService sut, CancellationToken dummyToken) { // Fixture setup // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(async () => await sut.SearchAsync(null, dummyToken)); // Teardown } To make sure that an ArgumentNullException is actually thrown I explicitly used a try-catch block. It worked, however the resulting code is not clean (compared to the first test):
[Theory, AutoWebData] public async Task SearchWithNullQueryThrows( SearchService sut, CancellationToken dummyToken) { // Fixture setup var expected = typeof(ArgumentNullException); Type actual = null; // Exercise system try { await sut.SearchAsync(null, dummyToken); } catch (ArgumentNullException e) { actual = e.GetType(); } // Verify outcome Assert.Equal(expected, actual); // Teardown } Why the Assert.Throws<T> with the lambda marked with the async modifier fails?
03e3be9a6781which is before the snapshot16883cb2351fwhere release2.0.0-alphahas been associated. However it still doesn't work after updating the solution with NuGet Package Manager.