我觉得应该是
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/