我想设置一个返回值
_stubRepository.Stub(Contains(null)).IgnoreArguments().Return(true);
Run Code Online (Sandbox Code Playgroud)
但是在特定测试中,覆盖该期望返回false.
就像是:
_stubRepository.ClearExpectations(); //<- this does not exist, I'm just making something up
_stubRepository.Stub(Contains(null)).IgnoreArguments().Return(false);
Run Code Online (Sandbox Code Playgroud)
注意,我不希望第二次调用时返回false,我想覆盖第一个期望.
这将有助于大大简化我的测试场景.
我可以在运行时更改存根的行为吗?就像是:
public interface IFoo { string GetBar(); }
[TestMethod]
public void TestRhino()
{
var fi = MockRepository.GenerateStub<IFoo>();
fi.Stub(x => x.GetBar()).Return("A");
Assert.AreEqual("A", fi.GetBar());
fi.Stub(x => x.GetBar()).Return("B");
Assert.AreEqual("B", fi.GetBar()); // Currently fails here
}
Run Code Online (Sandbox Code Playgroud)
我的代码示例仍然在给定的行中失败,fi.GetBar()仍然返回"A".
或者是否有另一种技巧来模拟其行为随时间变化的存根?我宁愿不求助于使用fi.Stub(...).Do(...).
啊,可能我只是需要硬拷贝的精美手册让某人用它来击打我.它看起来应该很明显,但我找不到它.