NSubstitute: Checking received methods with array arguments

拥有回忆 提交于 2019-11-30 17:10:57

I assume that your Commander object will take the arguments and puts them in an array which it then uses to call the Processor mock.

Your foos variable is another array which you create on your setup. Arrays don't compare equal to each other even if they have the same elements. So NSubstitute will complain that it didn't receive the expected value (it received another array which happened to contain the same elements).

Edit: Try this version:

//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(Arg.Is<Foo[]>(foos2 => foos.SequenceEqual(foos2));

This requires importing the System.Linq Namespace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!