Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSubstitute cannot determine argument specifications to use

I use NUnit and NSubstitute for unit testing. I have the following:

public interface IDataProvider
{
    void Log(int tvmId, DateTime time, int source, int level, int eventCode, string message);
}

...

var fakeDataProvider = Substitute.For<IDataProvider>();
...
fakeDataProvider.Received().Log(
    Arg.Any<int>(),
    new DateTime(2000, 1, 1),
    0,
    0,
    0,
    null);

fakeDataProvider.Received() throws AmbiguousArgumentException with the message that it cannot determine argument specifications to use. I have found the following on SO

Cannot determine argument specifications to use

which is related but I cannot apply it in the code above. Why is the above code ambiguous? How else could I specify to Received() that it should accept any argument?

like image 211
Drew Avatar asked Mar 24 '16 14:03

Drew


1 Answers

Since you have several int parameters in the Log method, you have to use the argument specification for each and every one of them.

fakeDataProvider.Received().Log(
    Arg.Any<int>(),
    new DateTime(2000, 1, 1),
    Arg.Is(0),
    Arg.Is(0),
    Arg.Is(0),
    null);
like image 65
Marcio Rinaldi Avatar answered Nov 13 '22 11:11

Marcio Rinaldi