1

创建访问器列表时出现一个非常奇怪的错误。
我有一个Component带有私有列表的课程Component。因为我想测试一些关于这个列表的类行为,所以我使用了Component-class 的访问器。此外,我在要避免的类的构造函数中有一些依赖项。TestInitialize()因此,我在-Method中手动实例化列表

TestInitialize() 代码如下所示:

private string _testIdentifier = "TestComponent";
private int _testConsist = 1;

private Component_Accessor _target;

[TestInitialize()]
    public void MyTestInitialize()
    {
        _target = new Component_Accessor();
        _target.Identifier = new ComponentIdentifier(_testIdentifier, _testConsist);
        _target._inputComponents = new List<Component_Accessor>();
        _target._outputComponents = new List<Component_Accessor>();
    }

访问器代码如下所示:

[Shadowing("_inputComponents")]  
public List<Component_Accessor> _inputComponents { get; set; }

这编译得很好,但我得到了一个 RunTimeException:

“System.Collections.Generic.List'1[DT5_Training_Simulator.Model.Components.Component_Accessor]”类型的对象无法转换为“System.Collections.Generic.List'1[DT5_Training_Simulator.Model.Components.Component]”类型]"

其实我在这里很茫然。谁能告诉我我做错了什么?

4

1 回答 1

0

您不能将Shadowing属性与公共成员一起使用,因为它会使测试人员感到困惑。据此Shadowing用于测试私有属性和方法,就好像它们是公共的一样。您的财产已经公开,因此您需要Shadowing从其声明中删除。

于 2011-12-13T15:13:06.607 回答