I have an issue with NSubstitute compiling using its inference typing. When I set it up with more than a return type in my .Do() statement and then try and use a counter to see how many times it is called, the counter isn’t updated.
I am mocking a method that returns a string (it’s basically an abstraction of File.ReadAllText()):
int fileReadCount =0;
IFileDataSource fs = Substitute.For<IFileDataSource>();
fs.When(x => x.ReadAllText(Arg.Any<string>())).Do(x =>
{
fileReadCount++;
return "test";
});
The alternate form mentioned in the documentation does seem to work either:
fs.ReadAllText("test").ReturnsForAnyArgs(x =>
{
fileReadCount++;
return "test";
});
My counter never changes.
I am following the examples from http://nsubstitute.github.com/help/return-from-function/ so I don’t understand what I am doing wrong – has the API changed?
This works for me in NSubstitute 1.1:
Can you post some more code to show the problem?