Cannot determine argument specifications to use

人盡茶涼 提交于 2019-12-24 01:19:06

问题


I'm having a problem with 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.

But instead, it throws an exception:

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? I am clearly providing a hint, that the argument can be any ReportingCycleDelivery item.


回答1:


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.



来源:https://stackoverflow.com/questions/15417883/cannot-determine-argument-specifications-to-use

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