1
以下使用是其成功通過使用ITestInterface
GenerateMock <T>和GenerateStub <T>哪一個在特定的情況下
ITestInterface mockProxy = MockRepository.GenerateMock<ITestInterface>();
或
簡單TestMethod的ITestInterface mockProxy = MockRepository.GenerateStub<ITestInterface>();
有人可以幫助我在使用哪一個這個特定的場景。
以下是用於測試業務層方法的TestMethod,x.Method是數據訪問層方法。
[TestMethod]
public void TestMethod1()
{
ITestInterface mockProxy = MockRepository.GenerateMock<ITestInterface>();
ITestInterface mockProxy = MockRepository.GenerateStub<ITestInterface>();
mockProxy.Stub(x => x.Method(Arg<int>.Is.Anything)).Return(10);
var result = mockProxy.BusinessLayerMethod(10);
Assert.AreEqual(10, result);
}
可能的dup http://stackoverflow.com/q/2536551/373706 – aqwert 2012-03-01 07:02:11