title: MsTest, DataSourceAttribute - how to get it working with a runtime generated file?
body: <p>for some test I need to run a data driven test with a configuration that is generated (via reflection) in the ClassInitialize method (by using reflection). I tried out everything, but I just can not get the data source properly set up.</p>
  
  <p>The test takes a list of classes in a csv file (one line per class) and then will test that the mappings to the database work out well (i.e. try to get one item from the database for every entity, which will throw an exception when the table structure does not match).</p>
  
  <p>The testmethod is:</p>
  
  <pre><code>[DataSource(
      "Microsoft.VisualStudio.TestTools.DataSource.CSV",
      "|DataDirectory|\\EntityMappingsTests.Types.csv",
      "EntityMappingsTests.Types#csv",
      DataAccessMethod.Sequential)
  ]
  [TestMethod()]
  public void TestMappings () {
  </code></pre>
  
  <p>Obviously the file is EntityMappingsTests.Types.csv. It should be in the DataDirectory.</p>
  
  <p>Now, in the Initialize method (marked with ClassInitialize) I put that together and then try to write it.</p>
  
  <p>WHERE should I write it to? WHERE IS THE DataDirectory?</p>
  
  <p>I tried:</p>
  
  <pre><code>File.WriteAllText(context.TestDeploymentDir + "\\EntityMappingsTests.Types.csv", types.ToString());
  File.WriteAllText("EntityMappingsTests.Types.csv", types.ToString());
  </code></pre>
  
  <p>Both result in "the unit test adapter failed to connect to the data source or read the data". More exact:</p>
  
  <blockquote>
    <p>Error details: The Microsoft Jet database engine could not find the
    object 'EntityMappingsTests.Types.csv'.  Make sure the object exists
    and that you spell its name and the path name correctly.</p>
  </blockquote>
  
  <p>So where should I put that file?</p>
  
  <p>I also tried just writing it to the current directory and taking out the DataDirectory part - same result. Sadly, there is limited debugging support here.</p>