gpt4 book ai didi

c# - 你如何使用 ShouldThrow

转载 作者:行者123 更新时间:2023-11-28 20:40:44 25 4
gpt4 key购买 nike

我觉得应该是

Should.Throw<ArgumentNullException>(module.Execute(badArgument));

但是当我尝试在 Should 类或命名空间上没有 Throw 方法时。

但是有几个方法,但是当我调用 ShouldThrow 时

Should.ActionAssertionExtensions
.ShouldThrow<ArgumentNullException>(() => module.Execute(badArgument));

它说这是一个不明确的调用,因为有两个 ShouldThrow 方法签名

void ShouldThrow<TException>(this Should.Core.Assertions.Assert.ThrowsDelegate)    
void ShouldThrow<TException>(this System.Action)

最佳答案

应该使用:

Action action = () => module.Execute(badArgument);    
action.ShouldThrow<ArgumentNullException>();

这些是在断言对象上调用的扩展方法。

关于c# - 你如何使用 ShouldThrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33989852/

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