我想编写测试来检查将与我们的项目一起交付的某些文件的存在(和其他东西)。是否有可能拥有Dynamic-On-The-Fly DeploymentItems?
这就是我现在所拥有的:
[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个文件,我不需要两个列表。
在此先感谢!
这个简单的例子是测试框架......但是,我将做的不仅仅是一个File.Exists()调用。我想简化问题的例子。 – Jeremiah 2009-07-16 13:13:42