I'm a bit stuck with this code (this is a sample):
public async Task Fail()
{
await Task.Run(() => { throw new Exception(); });
}
[Test]
public async Task TestFail()
{
Action a = async () => { await Fail(); };
a.ShouldThrow<Exception>();
}
The code doesn't catch the exception, and fails with
Expected a System.Exception to be thrown, but no exception was thrown.
I'm sure I'm missing something, but docs seem to suggest this is the way to go. Some help would be appreciated.
Assert.CatchAsync<Exception>(async () => await Fail());
– ConcisionAction
- this creates anasync void
method. The proper asynchronous delegate equivalent isFunc<Task>
. – AccurateFail
to callTask.Run
, it can just throw an exception, and there's no reason forTestFail
to have an anonymous method, you can just useFail
for the delegate without wrapping it in another method call that doesn't do anything. – Herold