是否可以拥有动态的即时部署项目?
我想编写测试来检查我们项目中附带的某些文件是否存在(以及其他内容)。
这就是我现在所拥有的:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您主要是在测试
[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...一种可能性是将文件放入子目录中,然后您可以获得部署项引用,例如
您可能还需要使用 CopyAlways 标记每个文件 - 有关详细信息,请参阅主要问题。
One possibility is to put your files into a subdirectory and then you can have the deployment item reference that e.g.
You might need to mark each file with the CopyAlways as well - see the main question for details.