【发布时间】:2012-02-29 12:27:04
【问题描述】:
请犀牛模拟专家帮忙。
下面的犀牛模拟示例运行良好。
internal class TestClass
{
private ITestInterface testInterface;
public TestClass(ITestInterface testInterface)
{
this.testInterface = testInterface;
}
public bool Method1(int x)
{
testInterface.Method1(x);
return true;
}
}
[TestClass]
public class UnitTest2
{
[TestMethod]
public void TestMethod1()
{
ITestInterface mockProxy = MockRepository.GenerateMock<ITestInterface>();
TestClass tc = new TestClass(mockProxy);
bool result = tc.Method1(5);
Assert.IsTrue(result);
mockProxy.AssertWasCalled(x => x.Method1(5));
}
}
根据上述代码,我面临的问题是我需要在所有子类中创建一个构造函数,如下所示:-.
internal class testclass1 : TestClass
{
protected testclass1(ITestInterface testInterface) : base(testInterface)
{
}
}
我有大约 50 个子类,有什么解决方法吗?
【问题讨论】:
-
如果我理解正确的话,问题不仅限于测试或模拟,而是一般的面向对象设计。
-
@AndreLoker 不完全是。我想知道rhino mock专家是如何处理这个问题的
标签: c# unit-testing mocking rhino-mocks