谁能解释一下为什么在 RhinoMocks 中这段代码仍然执行 native SomeVirtualMethod
?
var repository = MockRepository.GenerateStub<MyRepository>(null, null);
repository.Stub(x => x.SomeVirtualMethod()).Return(new List<SomeObject>());
当第二行运行时,原来的SomeVirtualMethod
运行并崩溃,因为它脱离了上下文。我也试过:
var repository = MockRepository.GenerateStub<MyRepository>(null, null);
repository.Stub(x => x.SomeVirtualMethod()).Do(new Func<List<SomeObject>>(() => new List<SomeObject>()));
如何确保只调用替代方法?