Tomasz Sikora
Tomasz Sikora

Reputation: 1767

Cannot determine argument specifications to use

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.

Upvotes: 2

Views: 4968

Answers (1)

Ryan Gates
Ryan Gates

Reputation: 4539

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.

Upvotes: 2

Related Questions