You’re seeing problems due to async void.
In particular:
-
async () => await userController.Get("foo")is converted intoTestDelegate, which returnsvoid, so your lambda expression is treated asasync void. So the test runner will begin executing the lambda but not wait for it to complete. The lambda returns beforeGetcompletes (because it’sasync), and the test runner sees that it returned without an exception. -
Waitwraps any exceptions in anAggregateException. -
Again, the
asynclambda is being treated asasync void, so the test runner is not waiting for its completion. -
I recommend you make this
async Taskrather thanasync void, but in this case the test runner does wait for completion, and thus sees the exception.
According to this bug report, there is a fix for this coming in the next build of NUnit. In the meantime, you can build your own ThrowsAsync method; an example for xUnit is here.