I am trying out moq and I have a question regarding to the Setup() method. I have the following interface and class:
public interface IMyInterface
{
void Print(string name);
}
public class MyClass
{
private IMyInterface my;
public MyClass(IMyInterface my)
{
this.my = my;
}
public void Print()
{
my.Print("hello world");
}
}
And I’ve got this unit test using NUnit:
[Test]
public void AnotherTest()
{
var mock = new Mock<IMyInterface>();
mock.Setup(m => m.Print("hello world")).AtMostOnce();
var myClass = new MyClass(mock.Object);
myClass.Print();
mock.Verify(m => m.Print("hello world"), Times.Exactly(1));
}
I’ve tried to both comment/uncomment out the below line and both tests were successful. It makes me wonder if Setup() is necessary in this case since I am doing the Verify()?
I am using version 3.5.716.1.