在调用Method之前调用了特定的构造函数

时间:2015-06-01 05:27:33

标签: c# rhino-mocks

class EmployeeBase : Base
{
    protected IDependency _dependency;

    ctor(IDependency dependency)
    {
       _dependency = dependency;
    }
    ctor(string name, int age)
    {
        base.Initialize("XXX " + name, "YYY" + Age);
    }


    IList<Emp> GetAllEmployees()
    {
       return _dependency.GetRecords();
    }
}

class FilteredEmployeeBase : EmployeeBase
{
    ctor(string name, int age) : base(name, age){}
    IList<Emp> GetMatchingEmployees()
    {
       return _dependency.GetRecords();
    }
}


// To Test Get GetMatchingEmployees, All i have to do is Inject IDependency and check assert was called on _dependency.GetRecords...

但这里的关键是......应该调用基类重载的构造函数 - 如何在Rhino Mocks中测试它

请注意:除了FilteredEmployeeBase,其余全部都是遗留代码&amp;我无法控制更改它们。

1 个答案:

答案 0 :(得分:0)

如果在不调用FilteredEmployeeBase.GetMatchingEmployees的基类构造函数的情况下调用dependency,则调用将在_dependency为空时失败。因此,我会说GetMatchingEmployees上的成功通话就足够了。或者我会错过什么?