With new FileInfo("C:\Path\To\An\Exe.exe")
you are creating a new object reference so what was executed with It.IsAny<FileInfo>()
and new FileInfo
are not same.
You can change the code as follows to use the same object.
public void TestSomething()
{
var programExecMock = new Mock<IExecution>();
var fileInfo = new FileInfo("C:\Path\To\An\Exe.exe");
var args = "--myParam 1";
programExecMock.Setup(pe => pe.ExecuteProgram(fileInfo, args )).Returns(true);
// Create the System under test "sut"
sut.CallSomething();
programExecMock.Verify(pe => pe.ExecuteProgram(fileInfo , args ), Times.Once);
}
Or alternatively change to following
programExecMock.Verify(pe => pe.ExecuteProgram(It.IsAny<FileInfo>(), It.IsAny<string()), Times.Once);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…