I am new to NSubtitute and really confused why below test case is failing.
public class IFoo {
public void SayHello(string to)
{
Console.writeLine("Method called");
}
}
[Test]
public void SayHello() {
var counter = 0;
var foo = Substitute.For<IFoo>();
foo.When(x => x.SayHello("World"))
.Do(x => counter++);
foo.SayHello("World");
foo.SayHello("World");
Assert.AreEqual(2, counter);
}
And it works for below code. Only difference is callback on method in class(Above case) and method in Interface(Below case).
public interface IFoo {
void SayHello(string to);
}
[Test]
public void SayHello() {
var counter = 0;
var foo = Substitute.For<IFoo>();
foo.When(x => x.SayHello("World"))
.Do(x => counter++);
foo.SayHello("World");
foo.SayHello("World");
Assert.AreEqual(2, counter);
}