vendredi 19 janvier 2018

Directory.Exists does not find directory when called from unit test

I am writing a test for an object method which checks that a directory exists before creating the object. The original program containing the unit under test is able to find the directory with no issue and the DirectoryInfo object (di) shows the proper bin location. When the object is created in the unit test however the FullPath attribute of the DirectoryInfo object di is: *C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7*

  public static string GetDataFilesDirectory()
  {
     string retVal = "";
     DirectoryInfo di = new DirectoryInfo( @"..\\" );
     if( Directory.Exists( "..\\Data Files\\" ) ) {
        retVal = "..\\Data Files";
     }
     else if( Directory.Exists( "..\\..\\..\\..\\Data Files\\" ) ) {
        retVal = "..\\..\\..\\..\\Data Files";
     }

     return retVal;
  }

The objective is to create the object and then invoke the method from it through reflection, which is NOT the issue. I am however unable to get the object to create since it needs this directory and in particular the files in it to instantiate.

Aucun commentaire:

Enregistrer un commentaire