我有一个测试,我会传递一个对象,例如:
var repo = new ActualRepo();
var sut = new Sut(repo);
在我的测试中,Repo有一个我需要实际执行的方法,而另一个方法我想要模拟并且不执行。
例如,看下这段伪代码:
var repo = new Mock<IRepo>();
repo.Setup(m => m.MethodIWantToCall()).WillBeExecuted();
repo.Setup(m => m.MethodIWantToMock()).Returns(false);
使用 Moq,这是否可能并且如何实现?
编辑: 我以前使用过 TypeMock,您可以执行以下操作。
Isolator.When(() => repo.MethodToIgnore()).WillBeIgnored();
Isolator.When(() => repo.MethodToActuallyRun()).WillBeExecuted();