/// <summary> /// Creates a ProjectFile with a given relative path, and a base path that will contain the /// relative path. Use this when given a relative path but not an absolute path. /// </summary> /// <param name="relativePath">A non-rooted path.</param> /// <param name="basePath"> /// A rooted path that will serve as the parent folder to the relative path. /// </param> /// <returns>A ProjectFile with a set AbsolutePath and RelativePath.</returns> public static ProjectFile FromRelativePath(string relativePath, string basePath) { var pf = new ProjectFile { RelativePath = relativePath }; pf.MakeAbsoluteWith(basePath); return pf; }
public void ProjectFile_ExternalRelativeFileCreationTest() { //Arrange const string pathToProjectFolder = "D:\\Test\\RelTest2"; const string relativePath1 = "../../Valentin/Videos/Wildlife.wmv"; const string expectedPath1 = "D:\\Valentin\\Videos\\Wildlife.wmv"; ProjectFile pf1; ProjectFile pf1a; //Act pf1 = ProjectFile.FromRelativePath(relativePath1, pathToProjectFolder); pf1a = new ProjectFile { RelativePath = relativePath1 }; pf1a.MakeAbsoluteWith(pathToProjectFolder); //Assert Assert.AreEqual(expectedPath1, pf1.AbsolutePath); Assert.AreEqual(expectedPath1, pf1a); }
public void ProjectFile_InternalRelativeFileCreationTest() { //Arrange const string pathToProjectFolder = "D:\\Test\\Wildlife"; const string relativePath1 = "Wildlife.wmv"; const string relativePath2 = "projectCache\\waveform.bin"; const string expectedAbsolutePath1 = "D:\\Test\\Wildlife\\Wildlife.wmv"; const string expectedAbsolutePath2 = "D:\\Test\\Wildlife\\projectCache\\waveform.bin"; ProjectFile pf1; ProjectFile pf1a; ProjectFile pf2; ProjectFile pf2a; //Act pf1 = ProjectFile.FromRelativePath(relativePath1, pathToProjectFolder); pf1a = new ProjectFile { RelativePath = relativePath1 }; pf1a.MakeAbsoluteWith(pathToProjectFolder); pf2 = ProjectFile.FromRelativePath(relativePath2, pathToProjectFolder); pf2a = new ProjectFile { RelativePath = relativePath2 }; pf2a.MakeAbsoluteWith(pathToProjectFolder); //Assert Assert.AreEqual(expectedAbsolutePath1, pf1.AbsolutePath); Assert.AreEqual(expectedAbsolutePath1, pf1a.AbsolutePath); Assert.AreEqual(expectedAbsolutePath2, pf2.AbsolutePath); Assert.AreEqual(expectedAbsolutePath2, pf2a.AbsolutePath); }