小编Jim*_*thy的帖子

NSubstitute:使用数组参数检查接收的方法

我想验证我的NSubstitute mock上的方法是否使用特定的数组参数调用.

说接口,IProcessor有一个方法void ProcessSomething(Foo[] something]).说我的课程被命名Commander.我设置了这样的测试:

//prepare
var processor = Substitute.For<IProcessor>;
var commander = new Commander(processor);
var foo1 = new Foo("alpha");
var foo2 = new Foo("bravo");
var foos = new [] {foo1, foo2};

//act
commander.DoSomething(foo1, foo2);

//verify
processor.Received().ProcessSomething(foos);  // FAILS
Run Code Online (Sandbox Code Playgroud)

Received()调用失败:

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive a call matching:
    ProcessSomething(Foo[])
Actually received no matching calls.
Received 1 non-matching call (non-matching arguments indicated with '*' characters):
    ProcessSomething(*Foo[]*)
Run Code Online (Sandbox Code Playgroud)

所以这看起来像ProcessSomething被调用除了一些数组foos,对吧?

好吧,如果我改为测试这个,我在哪里捕获参数值Arg.Do(),它成功:

//prepare …
Run Code Online (Sandbox Code Playgroud)

c# nsubstitute

39
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

nsubstitute ×1