gpt4 book ai didi

c# - 流畅的断言 Should().ThrowExactlyAsync 应该对于派生类型失败,但它不会

转载 作者:行者123 更新时间:2023-12-01 23:10:40 27 4
gpt4 key购买 nike

以下 Func 委托(delegate)抛出一个 ArgumentNullException:

Func<Task> act = async () => await _someService
.someMethod(1, 2, 3, 4);

使用 Fluent assertions ,断言:

act.Should().ThrowExactlyAsync<ArgumentException>();

应该失败:

Asserts that the current Func throws an exception of the exact type TException (and not a derived exception type).

ArgumentNullException 派生自 ArgumentException,根据描述,断言应该失败,但它通过了。

这是错误还是我误用了它?

最佳答案

由于 ThrowExactlyAsync 返回一个 Task,除非您 await 它,否则您实际上并没有做任何事情:

await act.Should().ThrowExactlyAsync<ArgumentException>();

关于c# - 流畅的断言 Should().ThrowExactlyAsync 应该对于派生类型失败,但它不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70006484/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com