我已经开始阅读“单元测试的艺术”,我正在尝试实现这段代码:
[Test]
public void ReturnResultsFromMock()
{
MockRepository mocks = new MockRepository();
IGetResults resultGetter = mocks.DynamicMock<IGetResults>();
using(mocks.Record())
{
resultGetter.GetSomeNumber("a");//#1
LastCall.Return(1);
resultGetter.GetSomeNumber("a");//#2 how it should work?
LastCall.Return(2);
resultGetter.GetSomeNumber("b");
LastCall.Return(3);
}
int result = resultGetter.GetSomeNumber("b");
Assert.AreEqual(3, result);
int result2 = resultGetter.GetSomeNumber("a");
Assert.AreEqual(1, result2);
int result3 = resultGetter.GetSomeNumber("a");
Assert.AreEqual(2, result3);
}
运行测试 AOUT.Loga.Tests.LogAnalyzerTest.ReturnResultsFromMock 后收到此错误消息 :预期:2 但为:1