views:

132

answers:

1

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!

+2  A: 

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...

Marc Gravell
This simple example is testing the framework...but, I will do more than just an File.Exists() call. I wanted to simplify the example for the question.
Jeremiah
How do you get the DeploymentItem's through reflection?
Jeremiah
GetType().GetCustomAttributes(typeof(DeploymentItemAttribute))
Marc Gravell