1

我尝试在多个源(.eml文件)上测试一种方法,并将它们保存在一个.resx文件中。我试图通过访问这些文件DataRows并将它们作为TestMethod参数传递,但 Visual Studio 吐出以下错误:An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type. 这基本上意味着我必须对所有[DataRow()]数据进行硬编码。有没有其他方法可以访问所有资源并对其进行测试?我目前的解决方法看起来像这样,但我觉得这不应该是如何访问所有资源的唯一有效选项:

private static List<byte[]> _List;
[ClassInitialize]
public static void ClassInit(TestContext tc)
{
    _List = new List<byte[]>
    {
        Resources.DisclaimerInWordSection,
        Resources.DisclaimerAboveWordSection,
        Resources.DisclaimerUnderneathWordSection
    };
}

这是我的TestMethod

[TestMethod]
public void GetDisclaimersAndIds_NoError()
{
    foreach (var bytes in _List)
    {
        Assert.IsNotNull(EmlInteractor.GetDisclaimersAndIds(bytes));
    }
}

提前致谢!

4

0 回答 0