How can I verify that the "CallWithRef" method was called using Moq?
public interface ITest
{
void CallWithoutRef(string value, List<string> errors);
void CallWithRef(string value, ref List<string> errors);
}
public class Foo
{
private ITest testInterface;
public Foo(ITest testInterface)
{
this.testInterface = testInterface;
}
public void DoStuff(string value)
{
var errorList = new List<string>();
testInterface.CallWithoutRef(value, errorList);
testInterface.CallWithRef(value, ref errorList);
}
}
[TestMethod]
public void VerifyTestInterfaceCalls()
{
var expectedValue = Path.GetRandomFileName();
var mockTestInterface = new Mock<ITest>();
var foo = new Foo(mockTestInterface.Object);
foo.DoStuff(expectedValue);
mockTestInterface.Verify(x => x.CallWithoutRef(expectedValue, It.IsAny<List<string>>()));
// Test fails here:
var errorList = It.IsAny<List<string>>();
mockTestInterface.Verify(x => x.CallWithRef(expectedValue, ref errorList));
}