Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 你如何使用shouldtown_C#_Unit Testing_Testing_Assertions - Fatal编程技术网

C# 你如何使用shouldtown

C# 你如何使用shouldtown,c#,unit-testing,testing,assertions,C#,Unit Testing,Testing,Assertions,我觉得应该是这样 Should.Throw<ArgumentNullException>(module.Execute(badArgument)); Should.Throw(module.Execute(badArgument)); 但是当我尝试在Should类或名称空间上没有Throw方法时 不过有两种方法,但是当我调用shouldtrow时 Should.ActionAssertionExtensions .ShouldThrow<ArgumentNullEx

我觉得应该是这样

Should.Throw<ArgumentNullException>(module.Execute(badArgument));
Should.Throw(module.Execute(badArgument));
但是当我尝试在Should类或名称空间上没有Throw方法时

不过有两种方法,但是当我调用shouldtrow时

Should.ActionAssertionExtensions
    .ShouldThrow<ArgumentNullException>(() => module.Execute(badArgument));
Should.ActionAssertionExtensions
.ShouldThrow(()=>module.Execute(badArgument));
它说这是一个模棱两可的调用,因为有两个ShouldThrow方法签名

void ShouldThrow<TException>(this Should.Core.Assertions.Assert.ThrowsDelegate)    
void ShouldThrow<TException>(this System.Action)
void ShouldThrow(这应该是.Core.Assertions.Assert.ThrowsDelegate)
void ShouldThrow(此系统操作)

应该使用:

Action action = () => module.Execute(badArgument);    
action.ShouldThrow<ArgumentNullException>();
Action Action=()=>module.Execute(badArgument);
动作。ShouldThrow();
这些是对被断言的对象调用的扩展方法