AFAICT、マイクロソフトはそれを含めるのを忘れただけです。それは確かにIMOにあるはずです(同意する場合は、UserVoice に投票してください)。
それまでの間、以下の方法を使用できます。それは私の AsyncEx ライブラリAsyncAssert
のクラスからのものです。近い将来、NuGet ライブラリとしてリリースする予定ですが、今のところ、これをテスト クラスに入れることができます。AsyncAssert
public static async Task ThrowsAsync<TException>(Func<Task> action, bool allowDerivedTypes = true)
{
try
{
await action();
Assert.Fail("Delegate did not throw expected exception " + typeof(TException).Name + ".");
}
catch (Exception ex)
{
if (allowDerivedTypes && !(ex is TException))
Assert.Fail("Delegate threw exception of type " + ex.GetType().Name + ", but " + typeof(TException).Name + " or a derived type was expected.");
if (!allowDerivedTypes && ex.GetType() != typeof(TException))
Assert.Fail("Delegate threw exception of type " + ex.GetType().Name + ", but " + typeof(TException).Name + " was expected.");
}
}