0

I have a project named SA.SEPA.UI.Selenium.Integration which contains a folder called Json Data Files that I wish to reference from both a unit test in that project, and a unit test in another project.

enter image description here

I'm having trouble getting the relative path.

With the following string I've tried to get to the folder....

private const string importFilePath = "..\\Json Data Files\\";

..however this returns a relative path of..

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Json Data Files.

How do I get the relative path of files in this folder that will work when accessing the folder from both a unit test in the project, and a unit test from another project (after a reference has been added)?

EDIT

Some code that uses the filepath...

public static List<T> GetAllRecords<T>(JsonType file)
{
    string filePath = $"{importFilePath}{file.ToJsonFile()}";

    List<T> jsonFileCollection;

    using (var r = new StreamReader(filePath))
    {
        string json = r.ReadToEnd();
        jsonFileCollection = JsonConvert.DeserializeObject<List<T>>(json);
    }

    return jsonFileCollection;
}

And the resultant error when debugging...

enter image description here

Konzy262
  • 2,747
  • 6
  • 42
  • 71
  • Have you considered adding the file as linked to the other project? https://msdn.microsoft.com/en-us/library/windows/apps/jj714082(v=vs.105).aspx – Rand Random Nov 20 '17 at 09:50
  • Could you show an example code that uses a variable `importFilePath` – Anton Gorbunov Nov 20 '17 at 09:50
  • Have you tried this: [https://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath](https://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath) – Hoang Tran Nov 20 '17 at 11:52

0 Answers0