Rhino mock an abstract class w/o mocking its virtual method?

前端 未结 2 837
孤独总比滥情好
孤独总比滥情好 2021-01-13 00:18

Can I execute the body of a virtual method that lives on an abstract class which has been mocked using Rhino Mocks?

To be clear, I\'m not trying to mock the behavior

2条回答
  •  余生分开走
    2021-01-13 00:25

    You need to tell Rhino.Mocks to call back to the original implementation instead of doing its default behavior of just intercepting the call:

    var mock = MockRepository.GenerateMock();
    mock.Setup(m => m.Foo()).CallOriginalMethod(OriginalCallOptions.NoExpectation);
    

    Now you can call the Foo() method on your mock object.

提交回复
热议问题