對於某些對象,我想創建默認存根,以便公共屬性包含值。但在某些情況下,我想覆蓋我的默認行爲。我的問題是,我能否以某種方式覆蓋已經存在的值?犀牛嘲諷屬性兩次
//First I create the default stub with a default value
var foo = MockRepository.GenerateStub<IFoo>();
foo.Stub(x => x.TheValue).Return(1);
//Somewhere else in the code I override the stubbed value
foo.Stub(x => x.TheValue).Return(2);
Assert.AreEqual(2, foo.TheValue); //Fails, since TheValue is 1
見http://stackoverflow.com/questions/770013/rhino-mocks-how-to-clear-以前對某個對象的期望 – Ted