如何在NSubstitute中测试忽略params参数的调用?

pen*_*uat 3 c# testing mocking nsubstitute

我的代码看起来像:

eventPublisher.Publish(new SpecificEvent(stuff),
                        EventStreams.Stream1,
                        EventStreams.Stream2);
Run Code Online (Sandbox Code Playgroud)

调用定义为的方法:

Publish<T>(T eventToPublish, params EventStream[] streams) where T : IEvent;
Run Code Online (Sandbox Code Playgroud)

在我想要测试的东西中.这个事件发布是我想要测试的最重要的事情,但我不想测试它发布到哪个事件流.我如何在NSubstitute中替代测试这个被适当的事件调用,而不用考虑自己的params?到目前为止,我有:

eventPublisher.Received(1).Publish(Arg.Any<SpecificEvent>());
Run Code Online (Sandbox Code Playgroud)

当然,这与两个流的呼叫不匹配.有没有办法使用NSubstitute匹配params参数,忽略传入的参数数量?

Val*_*tin 7

Params使方法能够接收可变数量的参数.使用时params,传递给方法的参数会被编译器更改为临时数组中的元素.然后在接收方法中使用该数组.

您可以使用Arg.Any<EventStream[]>匹配params参数,忽略传入的参数数量.

eventPublisher.Received(1).Publish(Arg.Any<SpecificEvent>(), Arg.Any<EventStream[]>)
Run Code Online (Sandbox Code Playgroud)