问题
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