简体   繁体   English

无法确定要使用的参数规范

[英]Cannot determine argument specifications to use

I'm having a problem with NSubstitute. 我在使用NSubstitute时遇到问题。 I have this short code: 我有这个短代码:

ReportingCycleDeliveryRepository
.When(f => f.Add(Arg.Any<ReportingCycleDelivery>()))
.Do(x => RepCycleDeliveries.Add((ReportingCycleDelivery)x[0]));

So when my (void) method ReportingCycleDeliveryRepository.Add() is invoked with any ReportingCycleDelivery argument, it should add this item to my RepCycleDeliveries list. 因此,当我的(无效)方法ReportingCycleDeliveryRepository.Add()与任何ReportingCycleDelivery参数一起调用时,它应该将此项目添加到我的RepCycleDeliveries列表中。

But instead, it throws an exception: 但是,它抛出一个异常:

NSubstitute.Exceptions.AmbiguousArgumentsException NSubstitute.Exceptions.AmbiguousArgumentsException

"Cannot determine argument specifications to use. Please use specifications for all arguments of the same type." “无法确定要使用的参数规范。请对所有相同类型的参数使用规范。”

Why is that? 这是为什么? Why can't NSubstitute determine the correct argument specifications to use? 为什么NSubstitute无法确定要使用的正确参数说明? I am clearly providing a hint, that the argument can be any ReportingCycleDelivery item. 我显然提供了一个提示,该参数可以是任何ReportingCycleDelivery项目。

You should be able to change your code to the following and have it work the way you would like it to: 您应该能够将代码更改为以下代码,并使代码按您希望的方式工作:

ReportingCycleDeliveryRepository
    .When(f => f.Add(Arg.Do<ReportingCycleDelivery>(
        x => RepCycleDeliveries.Add(x[0])));

It's hard to say exactly why you might get this error without seeing the code for ReportingCycleDeliveryRepository and ReportingCycleDelivery . 很难确切地说出为什么您会在没有看到ReportingCycleDeliveryRepositoryReportingCycleDelivery的代码的情况下出现此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM