是否可以拥有动态的即时部署项目?

发布于 2024-07-29 01:18:42 字数 828 浏览 2 评论 0原文

我想编写测试来检查我们项目中附带的某些文件是否存在(以及其他内容)。

这就是我现在所拥有的:

[DeploymentItem("1.pdf")]
[DeploymentItem("2.pdf")]    
public class DoFilesExist
{
    List<string> _Files;

    public DoFilesExist()
    {
        _Files = new List<string>();
        _Files.Add("1.pdf");
        _Files.Add("2.pdf");
    }

    delegate void fileTest(string fileName);

    void Map(fileTest test)
    {
        foreach (string file in _Files)
        {
            test(file);
        }            
    }

    [TestMethod]
    public void TestExists()
    {
        Map( x => Assert.IsTrue(File.Exists(x), x + " doesn't exist") );
    }
}

如您所见,当我想添加另一个文件进行测试时,我必须添加到 [DeploymentItem] 和 _Files 列表

有没有办法动态更改 DeploymentItems? 或者在运行时从它们中获取。 我可能最终会拥有超过 30 个文件,而且我不需要两个列表。

提前致谢!

I want to write tests to check the existance (and other stuff) of certain files that will be shipped with our project.

This is what I have right now:

[DeploymentItem("1.pdf")]
[DeploymentItem("2.pdf")]    
public class DoFilesExist
{
    List<string> _Files;

    public DoFilesExist()
    {
        _Files = new List<string>();
        _Files.Add("1.pdf");
        _Files.Add("2.pdf");
    }

    delegate void fileTest(string fileName);

    void Map(fileTest test)
    {
        foreach (string file in _Files)
        {
            test(file);
        }            
    }

    [TestMethod]
    public void TestExists()
    {
        Map( x => Assert.IsTrue(File.Exists(x), x + " doesn't exist") );
    }
}

As you can see, when I want to add another file to test, I have to add to the [DeploymentItem] and the _Files List

Is there a way to Dynamically Change the DeploymentItems? Or to grab from them during run time. I will probably end up having over 30 files here, and I do not want two lists.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不甘平庸 2024-08-05 01:18:42

看起来您主要是在测试 [DeploymentItem] 是否有效...毕竟 - 它不是 [DeploymentItem] 定义您的实际 部署。

就我个人而言,这是我鄙视MSTest的一点; .NET 项目已经拥有一种定义部署数据的方法 - 项目! 通过引入第二种方法,它会带来重复和风险。 我使用 NUnit 而不是 MSTest 的原因之一,即使我有 VSTS 许可证

重新回答这个问题; 您可以使用反射来查看 DeploymentItem 标记,但除了测试框架本身之外,我真的不确定这在测试什么......

It looks like you're mainly testing whether [DeploymentItem] works... after all - it isn't [DeploymentItem] that defines your actual deployment.

Personally, this is something I despise about MSTest; .NET projects already have a way to define deployment data - the project! By introducing a second method, it introduces both duplication and risk. One of the reasons I use NUnit instead of MSTest, even though I have a VSTS license </rant>.

Re the question; you could use reflection to look at the DeploymentItem markers, but I'm really not sure what this is testing, other than the test framework itself...

洛阳烟雨空心柳 2024-08-05 01:18:42

一种可能性是将文件放入子目录中,然后您可以获得部署项引用,例如

[DeploymentItem("files\"]
public class Test
{
}

您可能还需要使用 CopyAlways 标记每个文件 - 有关详细信息,请参阅主要问题。

One possibility is to put your files into a subdirectory and then you can have the deployment item reference that e.g.

[DeploymentItem("files\"]
public class Test
{
}

You might need to mark each file with the CopyAlways as well - see the main question for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文