解决方法
是的,这应该是绝对正常的.我不能说我已经尝试过了,但如果它失败了我会很惊讶.
编辑:我怀疑你想要PartialMock方法.这是一个例子:
using System; using Rhino.Mocks; public abstract class Abstract { public virtual int Foo() { return Bar() * 2; } public abstract int Bar(); } class Test { static void Main(string[] args) { MockRepository repository = new MockRepository(); Abstract mock = repository.PartialMock<Abstract>(); using (repository.Record()) { Expect.Call(mock.Bar()).Return(5); } Console.WriteLine(mock.Foo()); // Prints 10 } }
编辑:或者在我第一次尝试AAA时:
using System; using Rhino.Mocks; public abstract class Abstract { public virtual int Foo() { return Bar() * 2; } public abstract int Bar(); } class Test { static void Main(string[] args) { // Arrange Abstract mock = MockRepository.GeneratePartialMock<Abstract>(); mock.Stub(action => action.Bar()).Return(5); // Act int result = mock.Foo(); // Assert mock.AssertWasCalled(x => x.Bar()); // And assert that result is 10... } }