I used FluentAssertions; it's great! :) I particularly like using the .Invoking().Should().Throw<Exception>()
pattern it provides.
I wrote this line in my test:
myObject.Invoking(r => r.SomeAsyncFunc()).Should().NotThrowAsync();
Where .SomeAsyncFunc
is declared using the async
keyword and makes use of the await
keyword internally.
And it all passed, and I was very happy. And then I thought to verify that the test was doing what I thought it did, so I added code to force SomeAsyncFunc()
to immediately throw. (before hitting any await
keywords).
It still passed. This made me sad :(
I tried the following formulations, all of which also passed:
myObject.Invoking(r => r.SomeAsyncFunc()).Should().NotThrowAsync();
myObject.Invoking(async r => await r.SomeAsyncFunc()).Should().NotThrowAsync();
myObject.Awaiting(r => r.SomeAsyncFunc()).Should().NotThrowAsync();
myObject.Awaiting((Func<MyObject, Task>)(async r => await r.SomeAsyncFunc())).Should().NotThrowAsync();
Whereas is if I do this, then it DOES work ... but that feels very wrong!
myObject.Invoking(r => r.SomeAsyncFunc()).Should().NotThrow();
What have I mis-understood?