如何使用Rhino.Mocks模拟受保护的虚拟成员?

Vad*_*dim 6 rhino-mocks moq mocking

Moq允许开发人员模拟受保护的成员.我在Rhino.Mocks中寻找相同的功能但却找不到它.

以下是Moq快速入门页面如何模拟受保护方法的示例.

// at the top of the test fixture
using Moq.Protected()

// in the test
var mock = new Mock<CommandBase>();
mock.Protected()
     .Setup<int>("Execute")
     .Returns(5);

// if you need argument matching, you MUST use ItExpr rather than It
// planning on improving this for vNext
mock.Protected()
    .Setup<string>("Execute",
        ItExpr.IsAny<string>())
    .Returns(true);
Run Code Online (Sandbox Code Playgroud)

如果我正在追逐不退出的东西,请告诉我.

Grz*_*nio 4

我相信 Rhino Mocks 中不存在此功能。

你为什么要嘲笑受保护的成员?为什么不直接测试整个班级呢?或者,您可以创建测试类的子类并手动创建“模拟”受保护方法。