예제 #1
0
        public void Test_GetAbsolutePath()
        {
            DirectoryPathRelative directoryPathTo;
            DirectoryPathAbsolute directoryPathFrom;

            directoryPathTo   = new DirectoryPathRelative(@"..");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:");
            Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            directoryPathTo   = new DirectoryPathRelative(@".");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1");
            Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            directoryPathTo   = new DirectoryPathRelative(@"..\Dir2");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir2");
            Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            directoryPathTo   = new DirectoryPathRelative(@"..\..\Dir4\Dir5");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
            Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir4\Dir5");
            Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            directoryPathTo   = new DirectoryPathRelative(@".\..\Dir4\Dir5");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
            Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir2\Dir4\Dir5");
            Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
        }
예제 #2
0
        public void Test_GetAbsolutePathPathWithError6()
        {
            DirectoryPathRelative directoryPathTo = new DirectoryPathRelative(@"..\..\Dir1");

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(null));
            directoryPathTo.GetAbsolutePathFrom(null);
        }
예제 #3
0
        public void Test_IncoherentPathModeException2()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidRelativePath(@"C:\", out reason));
            DirectoryPath directoryPath = new DirectoryPathRelative(@"C:\");
        }
예제 #4
0
        public void Test_GetAbsolutePathPathWithError5()
        {
            DirectoryPathRelative directoryPathTo   = DirectoryPathRelative.Empty;
            DirectoryPathAbsolute directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
            directoryPathTo.GetAbsolutePathFrom(directoryPathFrom);
        }
예제 #5
0
        public void Test_EmptyDirectoryPathRelative()
        {
            DirectoryPathRelative directoryPath = DirectoryPathRelative.Empty;

            Assert.IsTrue(directoryPath.IsEmpty);
            Assert.IsTrue(directoryPath.IsRelativePath);
            Assert.IsTrue(directoryPath.IsDirectoryPath);
            Assert.IsFalse(directoryPath.IsFilePath);
        }
예제 #6
0
        public void Test_GetChildWithName()
        {
            DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");

            Assert.IsTrue(directoryPathAbsolute.GetChildFileWithName("File.txt").Path == @"C:\Dir1\Dir2\File.txt");
            Assert.IsTrue(directoryPathAbsolute.GetChildDirectoryWithName("Dir3").Path == @"C:\Dir1\Dir2\Dir3");

            DirectoryPathRelative directoryPathRelative = new DirectoryPathRelative(@"..\..\Dir1\Dir2");

            Assert.IsTrue(directoryPathRelative.GetChildFileWithName("File.txt").Path == @"..\..\Dir1\Dir2\File.txt");
            Assert.IsTrue(directoryPathRelative.GetChildDirectoryWithName("Dir3").Path == @"..\..\Dir1\Dir2\Dir3");
        }
예제 #7
0
        public void Test_PathModeOk()
        {
            DirectoryPath path = new DirectoryPathRelative(@".");

            Assert.IsTrue(path.IsRelativePath);

            path = new DirectoryPathAbsolute(@"C:\");
            Assert.IsTrue(path.IsAbsolutePath);

            path = new DirectoryPathRelative(@".\dir...1");
            Assert.IsTrue(path.IsRelativePath);

            path = new DirectoryPathAbsolute(@"C:\dir...1");
            Assert.IsTrue(path.IsAbsolutePath);
        }
예제 #8
0
        public void TestDirectoryName()
        {
            string directoryName = new DirectoryPathRelative(@".\").DirectoryName;
             Assert.IsTrue(directoryName == string.Empty);

             directoryName = new DirectoryPathAbsolute(@"C:\").DirectoryName;
             Assert.IsTrue(directoryName == string.Empty);

             directoryName = new DirectoryPathRelative(@".\\dir1\\/dir2").DirectoryName;
             Assert.IsTrue(directoryName == @"dir2");

             directoryName = new DirectoryPathAbsolute(@"C:\\\\dir1").DirectoryName;
             Assert.IsTrue(directoryName == @"dir1");

             directoryName = new DirectoryPathAbsolute(@"C:\dir1\\//dir2\").DirectoryName;
             Assert.IsTrue(directoryName == @"dir2");
        }
예제 #9
0
        public void Test_HasParentDir()
        {
            DirectoryPath path = new DirectoryPathRelative(@".\");

            Assert.IsFalse(path.HasParentDir);

            path = new DirectoryPathRelative(@".\Dir1");
            Assert.IsTrue(path.HasParentDir);

            path = new DirectoryPathRelative(@".\Dir1\Dir");
            Assert.IsTrue(path.HasParentDir);

            path = new DirectoryPathAbsolute(@"C:\\");
            Assert.IsFalse(path.HasParentDir);

            path = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(path.HasParentDir);
        }
예제 #10
0
        public void TestDirectoryName()
        {
            string directoryName = new DirectoryPathRelative(@".\").DirectoryName;

            Assert.IsTrue(directoryName == string.Empty);

            directoryName = new DirectoryPathAbsolute(@"C:\").DirectoryName;
            Assert.IsTrue(directoryName == string.Empty);

            directoryName = new DirectoryPathRelative(@".\\dir1\\/dir2").DirectoryName;
            Assert.IsTrue(directoryName == @"dir2");

            directoryName = new DirectoryPathAbsolute(@"C:\\\\dir1").DirectoryName;
            Assert.IsTrue(directoryName == @"dir1");

            directoryName = new DirectoryPathAbsolute(@"C:\dir1\\//dir2\").DirectoryName;
            Assert.IsTrue(directoryName == @"dir2");
        }
예제 #11
0
        public void Test_NormalizePath()
        {
            DirectoryPath path = new DirectoryPathRelative(@".\");

            Assert.IsTrue(path.Path == ".");

            path = new DirectoryPathRelative(@".\\\");
            Assert.IsTrue(path.Path == ".");

            path = new DirectoryPathRelative(@".\\\..\\");
            Assert.IsTrue(path.Path == @".\..");

            path = new DirectoryPathRelative(@".\/dir1\//\dir2\/dir3///");
            Assert.IsTrue(path.Path == @".\dir1\dir2\dir3");

            path = new DirectoryPathAbsolute(@"C:/dir1/dir2");
            Assert.IsTrue(path.Path == @"C:\dir1\dir2");
        }
예제 #12
0
        public void Test_ParentDirectoryPath()
        {
            DirectoryPath path = new FilePathRelative(@".\Dir1").ParentDirectoryPath;

            Assert.IsTrue(path.Path == @".");

            path = new DirectoryPathRelative(@".\Dir1\\Dir2").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @".\Dir1");

            path = new DirectoryPathAbsolute(@"C:\Dir1").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @"C:");

            path = new DirectoryPathRelative(@".\\Dir1").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @".");

            path = new DirectoryPathAbsolute(@"C:\\\\Dir1\\Dir2").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @"C:\Dir1");

            path = new DirectoryPathAbsolute(@"C:\dir1\\//dir2\").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @"C:\dir1");
        }
예제 #13
0
        public void Test_GetChildWithName()
        {
            DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
             Assert.IsTrue(directoryPathAbsolute.GetChildFileWithName("File.txt").Path == @"C:\Dir1\Dir2\File.txt");
             Assert.IsTrue(directoryPathAbsolute.GetChildDirectoryWithName("Dir3").Path == @"C:\Dir1\Dir2\Dir3");

             DirectoryPathRelative directoryPathRelative = new DirectoryPathRelative(@"..\..\Dir1\Dir2");
             Assert.IsTrue(directoryPathRelative.GetChildFileWithName("File.txt").Path == @"..\..\Dir1\Dir2\File.txt");
             Assert.IsTrue(directoryPathRelative.GetChildDirectoryWithName("Dir3").Path == @"..\..\Dir1\Dir2\Dir3");
        }
예제 #14
0
        public void Test_HasParentDir()
        {
            DirectoryPath path = new DirectoryPathRelative(@".\");
             Assert.IsFalse(path.HasParentDir);

             path = new DirectoryPathRelative(@".\Dir1");
             Assert.IsTrue(path.HasParentDir);

             path = new DirectoryPathRelative(@".\Dir1\Dir");
             Assert.IsTrue(path.HasParentDir);

             path = new DirectoryPathAbsolute(@"C:\\");
             Assert.IsFalse(path.HasParentDir);

             path = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(path.HasParentDir);
        }
예제 #15
0
        public void Test_GetChildWithName_Error9()
        {
            DirectoryPathRelative directoryPathRelative = new DirectoryPathRelative(@"..\Dir1\Dir2");

            directoryPathRelative.GetChildDirectoryWithName(String.Empty);
        }
예제 #16
0
 public void Test_Error1OnParentDirectoryPath()
 {
     DirectoryPath path = new DirectoryPathRelative(@".\").ParentDirectoryPath;
 }
예제 #17
0
        public void Test_GetAbsolutePath()
        {
            DirectoryPathRelative directoryPathTo;
             DirectoryPathAbsolute directoryPathFrom;

             directoryPathTo = new DirectoryPathRelative(@"..");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:");
             Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             directoryPathTo = new DirectoryPathRelative(@".");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1");
             Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             directoryPathTo = new DirectoryPathRelative(@"..\Dir2");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir2");
             Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             directoryPathTo = new DirectoryPathRelative(@"..\..\Dir4\Dir5");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
             Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir4\Dir5");
             Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             directoryPathTo = new DirectoryPathRelative(@".\..\Dir4\Dir5");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
             Assert.IsTrue(directoryPathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir2\Dir4\Dir5");
             Assert.IsTrue(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
        }
예제 #18
0
 public void Test_InnerSpecialDir_Error40()
 {
     BasePath path = new DirectoryPathRelative(@".\..\Dir1\..\..");
 }
예제 #19
0
        public void Test_PathModeOk()
        {
            DirectoryPath path = new DirectoryPathRelative(@".");
             Assert.IsTrue(path.IsRelativePath);

             path = new DirectoryPathAbsolute(@"C:\");
             Assert.IsTrue(path.IsAbsolutePath);

             path = new DirectoryPathRelative(@".\dir...1");
             Assert.IsTrue(path.IsRelativePath);

             path = new DirectoryPathAbsolute(@"C:\dir...1");
             Assert.IsTrue(path.IsAbsolutePath);
        }
예제 #20
0
        public void Test_PathEquality()
        {
            Assert.IsFalse(DirectoryPathAbsolute.Empty.Equals(null));
             Assert.IsFalse(DirectoryPathAbsolute.Empty == null);

             Assert.IsTrue(DirectoryPathAbsolute.Empty.Equals(DirectoryPathRelative.Empty));
             Assert.IsTrue(DirectoryPathAbsolute.Empty == DirectoryPathRelative.Empty);

             Assert.IsFalse(DirectoryPathAbsolute.Empty.Equals(new DirectoryPathRelative(@"..\Dir1\Dir2")));
             Assert.IsFalse(DirectoryPathAbsolute.Empty == new DirectoryPathRelative(@"..\Dir1\Dir2"));

             //
             // directoryPathRelative
             //
             DirectoryPathRelative directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
             DirectoryPathRelative directoryPathRelative2 = new DirectoryPathRelative(@"..\\dir1//DIR2/");
             Assert.IsTrue(directoryPathRelative1.Equals(directoryPathRelative2));
             Assert.IsTrue(directoryPathRelative1 == directoryPathRelative2);

             directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
             directoryPathRelative2 = new DirectoryPathRelative(@".\Dir1\Dir2");
             Assert.IsFalse(directoryPathRelative1.Equals(directoryPathRelative2));
             Assert.IsFalse(directoryPathRelative1 == directoryPathRelative2);

             directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
             directoryPathRelative2 = new DirectoryPathRelative(@"..\Dir1\Dir2\Dir3");
             Assert.IsFalse(directoryPathRelative1.Equals(directoryPathRelative2));
             Assert.IsTrue(directoryPathRelative1 != directoryPathRelative2);

             directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
             directoryPathRelative2 = new DirectoryPathRelative(@"..\Dir1\Dir");
             Assert.IsFalse(directoryPathRelative1.Equals(directoryPathRelative2));
             Assert.IsTrue(directoryPathRelative1 != directoryPathRelative2);

             //
             // directoryPathAbsolute
             //
             DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
             DirectoryPathAbsolute directoryPathAbsolute2 = new DirectoryPathAbsolute(@"C:\\dir1//Dir2\\");
             Assert.IsTrue(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
             Assert.IsFalse(directoryPathAbsolute1 != directoryPathAbsolute2);

             directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
             directoryPathAbsolute2 = new DirectoryPathAbsolute(@"D:\Dir1\Dir2");
             Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
             Assert.IsFalse(directoryPathAbsolute1 == directoryPathAbsolute2);

             directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
             directoryPathAbsolute2 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir2");
             Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
             Assert.IsFalse(directoryPathAbsolute1 == directoryPathAbsolute2);

             directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
             directoryPathAbsolute2 = new DirectoryPathAbsolute(@"C:\Dir1\Dir");
             Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
             Assert.IsFalse(directoryPathAbsolute1 == directoryPathAbsolute2);

             //
             // Mix between directoryPathAbsolute and directoryPathRelative
             //
             directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
             directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
             Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathRelative1));
             Assert.IsFalse(directoryPathAbsolute1 == directoryPathRelative1);
        }
예제 #21
0
        public void Test_ParentDirectoryPath()
        {
            DirectoryPath path = new FilePathRelative(@".\Dir1").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".");

             path = new DirectoryPathRelative(@".\Dir1\\Dir2").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".\Dir1");

             path = new DirectoryPathAbsolute(@"C:\Dir1").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:");

             path = new DirectoryPathRelative(@".\\Dir1").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".");

             path = new DirectoryPathAbsolute(@"C:\\\\Dir1\\Dir2").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:\Dir1");

             path = new DirectoryPathAbsolute(@"C:\dir1\\//dir2\").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:\dir1");
        }
예제 #22
0
        public void Test_NormalizePath()
        {
            DirectoryPath path = new DirectoryPathRelative(@".\");
             Assert.IsTrue(path.Path == ".");

             path = new DirectoryPathRelative(@".\\\");
             Assert.IsTrue(path.Path == ".");

             path = new DirectoryPathRelative(@".\\\..\\");
             Assert.IsTrue(path.Path == @".\..");

             path = new DirectoryPathRelative(@".\/dir1\//\dir2\/dir3///");
             Assert.IsTrue(path.Path == @".\dir1\dir2\dir3");

             path = new DirectoryPathAbsolute(@"C:/dir1/dir2");
             Assert.IsTrue(path.Path == @"C:\dir1\dir2");
        }
예제 #23
0
 public void Test_IncoherentPathModeException2()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidRelativePath(@"C:\", out reason));
      DirectoryPath directoryPath = new DirectoryPathRelative(@"C:\");
 }
예제 #24
0
 public void Test_GetAbsolutePathPathWithError6()
 {
     DirectoryPathRelative directoryPathTo = new DirectoryPathRelative(@"..\..\Dir1");
      Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(null));
      directoryPathTo.GetAbsolutePathFrom(null);
 }
예제 #25
0
 public void Test_GetAbsolutePathPathWithError4()
 {
     DirectoryPathRelative directoryPathTo = new DirectoryPathRelative(@"..\..\Dir1");
      DirectoryPathAbsolute directoryPathFrom = DirectoryPathAbsolute.Empty;
      Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
      directoryPathTo.GetAbsolutePathFrom(directoryPathFrom);
 }
예제 #26
0
        public void Test_PathEquality()
        {
            //
             // filePathRelative
             //
             FilePathRelative filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             FilePathRelative filePathRelative2 = new FilePathRelative(@"..\\dir1//file.TXT");
             Assert.IsTrue(filePathRelative1.Equals(filePathRelative2));
             Assert.IsTrue(filePathRelative1 == filePathRelative2);

             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathRelative2 = new FilePathRelative(@".\Dir1\File.txt");
             Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
             Assert.IsFalse(filePathRelative1 == filePathRelative2);

             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathRelative2 = new FilePathRelative(@"..\Dir1\Dir2\File.txt");
             Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
             Assert.IsFalse(filePathRelative1 == filePathRelative2);

             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathRelative2 = new FilePathRelative(@"..\Dir1\File.tx");
             Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
             Assert.IsFalse(filePathRelative1 == filePathRelative2);

             //
             // filePathAbsolute
             //
             FilePathAbsolute filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             FilePathAbsolute filePathAbsolute2 = new FilePathAbsolute(@"C:\\dir1//file.TXT");
             Assert.IsTrue(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsTrue(filePathAbsolute1 == filePathAbsolute2);

             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             filePathAbsolute2 = new FilePathAbsolute(@"D:\Dir1\File.txt");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\Dir2\File.txt");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\File.tx");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

             //
             // Mix between filePathAbsolute and filePathRelative
             //
             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathRelative1));
             Assert.IsFalse(filePathAbsolute1 == filePathRelative1);

             //
             // Mix between directoryPath and filePath
             //
             DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\File");
             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File");
             Assert.IsFalse(directoryPathAbsolute1.Equals(filePathAbsolute1));
             Assert.IsFalse(filePathAbsolute1.Equals(directoryPathAbsolute1));
             Assert.IsFalse(filePathAbsolute1 == directoryPathAbsolute1);

             DirectoryPathRelative directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\File");
             filePathRelative1 = new FilePathRelative(@"..\Dir1\File");
             Assert.IsFalse(directoryPathRelative1.Equals(filePathRelative1));
             Assert.IsFalse(filePathRelative1.Equals(directoryPathRelative1));
             Assert.IsFalse(filePathRelative1 == directoryPathRelative1);
        }
예제 #27
0
        public void Test_PathEquality()
        {
            Assert.IsFalse(DirectoryPathAbsolute.Empty.Equals(null));
            Assert.IsFalse(DirectoryPathAbsolute.Empty == null);

            Assert.IsTrue(DirectoryPathAbsolute.Empty.Equals(DirectoryPathRelative.Empty));
            Assert.IsTrue(DirectoryPathAbsolute.Empty == DirectoryPathRelative.Empty);

            Assert.IsFalse(DirectoryPathAbsolute.Empty.Equals(new DirectoryPathRelative(@"..\Dir1\Dir2")));
            Assert.IsFalse(DirectoryPathAbsolute.Empty == new DirectoryPathRelative(@"..\Dir1\Dir2"));

            //
            // directoryPathRelative
            //
            DirectoryPathRelative directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
            DirectoryPathRelative directoryPathRelative2 = new DirectoryPathRelative(@"..\\dir1//DIR2/");

            Assert.IsTrue(directoryPathRelative1.Equals(directoryPathRelative2));
            Assert.IsTrue(directoryPathRelative1 == directoryPathRelative2);

            directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
            directoryPathRelative2 = new DirectoryPathRelative(@".\Dir1\Dir2");
            Assert.IsFalse(directoryPathRelative1.Equals(directoryPathRelative2));
            Assert.IsFalse(directoryPathRelative1 == directoryPathRelative2);

            directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
            directoryPathRelative2 = new DirectoryPathRelative(@"..\Dir1\Dir2\Dir3");
            Assert.IsFalse(directoryPathRelative1.Equals(directoryPathRelative2));
            Assert.IsTrue(directoryPathRelative1 != directoryPathRelative2);

            directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
            directoryPathRelative2 = new DirectoryPathRelative(@"..\Dir1\Dir");
            Assert.IsFalse(directoryPathRelative1.Equals(directoryPathRelative2));
            Assert.IsTrue(directoryPathRelative1 != directoryPathRelative2);

            //
            // directoryPathAbsolute
            //
            DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
            DirectoryPathAbsolute directoryPathAbsolute2 = new DirectoryPathAbsolute(@"C:\\dir1//Dir2\\");

            Assert.IsTrue(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
            Assert.IsFalse(directoryPathAbsolute1 != directoryPathAbsolute2);

            directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
            directoryPathAbsolute2 = new DirectoryPathAbsolute(@"D:\Dir1\Dir2");
            Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
            Assert.IsFalse(directoryPathAbsolute1 == directoryPathAbsolute2);

            directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
            directoryPathAbsolute2 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir2");
            Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
            Assert.IsFalse(directoryPathAbsolute1 == directoryPathAbsolute2);

            directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
            directoryPathAbsolute2 = new DirectoryPathAbsolute(@"C:\Dir1\Dir");
            Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathAbsolute2));
            Assert.IsFalse(directoryPathAbsolute1 == directoryPathAbsolute2);

            //
            // Mix between directoryPathAbsolute and directoryPathRelative
            //
            directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
            directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2");
            Assert.IsFalse(directoryPathAbsolute1.Equals(directoryPathRelative1));
            Assert.IsFalse(directoryPathAbsolute1 == directoryPathRelative1);
        }
예제 #28
0
 public void Test_GetChildWithName_Error8()
 {
     DirectoryPathRelative directoryPathRelative = new DirectoryPathRelative(@"..\Dir1\Dir2");
      directoryPathRelative.GetChildDirectoryWithName(null);
 }
예제 #29
0
        public void Test_GetChildWithName_Error8()
        {
            DirectoryPathRelative directoryPathRelative = new DirectoryPathRelative(@"..\Dir1\Dir2");

            directoryPathRelative.GetChildDirectoryWithName(null);
        }
예제 #30
0
 public void Test_Error1OnParentDirectoryPath()
 {
     DirectoryPath path = new DirectoryPathRelative(@".\").ParentDirectoryPath;
 }
예제 #31
0
   static void Main(string[] args) {
      FilePathAbsolute filePathAbsolute1, filePathAbsolute2;
      FilePathRelative filePathRelative1;
      DirectoryPathAbsolute directoryPathAbsolute1;
      DirectoryPathRelative directoryPathRelative1;



      //  Path normalization
      filePathAbsolute1 = new FilePathAbsolute(@"C:/Dir1\\File.txt");
      Debug.Assert(filePathAbsolute1.Path == @"C:\Dir1\File.txt");

      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:/Dir1\\Dir2\");
      Debug.Assert(directoryPathAbsolute1.Path == @"C:\Dir1\Dir2");

      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\..\Dir2\.");
      Debug.Assert(directoryPathAbsolute1.Path == @"C:\Dir2");



      // Path comparison
      filePathAbsolute1 = new FilePathAbsolute(@"C:/Dir1\\File.txt");
      filePathAbsolute2 = new FilePathAbsolute(@"C:\DIR1\FILE.TXT");
      Debug.Assert(filePathAbsolute1.Equals(filePathAbsolute2));
      Debug.Assert(filePathAbsolute1 == filePathAbsolute2);



      // Relative -> Absolute path conversion
      filePathRelative1 = new FilePathRelative(@"..\..\Dir1\File.txt");
      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir2\Dir3\Dir4");
      filePathAbsolute1 = filePathRelative1.GetAbsolutePathFrom(directoryPathAbsolute1);
      Debug.Assert( filePathAbsolute1.Path == @"C:\Dir2\Dir1\File.txt");



      // Absolute -> Relative path conversion
      filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir2\Dir3\Dir4");
      filePathRelative1 = filePathAbsolute1.GetPathRelativeFrom(directoryPathAbsolute1);
      Debug.Assert(filePathRelative1.Path == @"..\..\..\Dir1\File.txt");



      // Path string validation
      string reason;
      Debug.Assert(PathHelper.IsValidAbsolutePath(@"C:\Dir2\Dir1", out reason));
      Debug.Assert(!PathHelper.IsValidAbsolutePath(@"C:\..\Dir1", out reason));
      Debug.Assert(!PathHelper.IsValidAbsolutePath(@".\Dir1", out reason));
      Debug.Assert(!PathHelper.IsValidAbsolutePath(@"1:\Dir1", out reason));
      Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\Dir2", out reason));
      Debug.Assert(PathHelper.IsValidRelativePath(@"..\Dir1\Dir2", out reason));
      Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\..\Dir2", out reason));
      Debug.Assert(!PathHelper.IsValidRelativePath(@".\Dir1\..\..\Dir2", out reason));
      Debug.Assert(!PathHelper.IsValidRelativePath(@"C:\Dir1\Dir2", out reason));



      // File name & extension
      filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.cs.Txt");
      Debug.Assert(filePathAbsolute1.FileName == "File.cs.Txt");
      Debug.Assert(filePathAbsolute1.FileNameWithoutExtension == "File.cs");
      Debug.Assert(filePathAbsolute1.FileExtension == ".Txt");
      Debug.Assert(filePathAbsolute1.HasExtension(".txt"));



      // Path browsing
      filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.cs.Txt");
      Debug.Assert(filePathAbsolute1.ParentDirectoryPath.Path == @"C:\Dir1");
      Debug.Assert(filePathAbsolute1.GetBrotherFileWithName("File.xml").Path == @"C:\Dir1\File.xml");
      Debug.Assert(filePathAbsolute1.ParentDirectoryPath.GetChildDirectoryWithName("Dir2").Path == @"C:\Dir1\Dir2");
      Debug.Assert(filePathAbsolute1.ParentDirectoryPath.GetChildDirectoryWithName("..").Path == @"C:");

      directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
      Debug.Assert(directoryPathRelative1.ParentDirectoryPath.Path == @"..\Dir1");



      // Path rebasing
      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
      DirectoryPathAbsolute directoryPathAbsolute2 = new DirectoryPathAbsolute(@"E:\Dir4\Dir1");
      DirectoryPathAbsolute rebasedPath;
      PathHelper.TryRebasePath(directoryPathAbsolute1, directoryPathAbsolute2, out rebasedPath);
      Debug.Assert(rebasedPath.Path == @"E:\Dir4\Dir1\Dir2\Dir3");


      // List of path  ListOfPathsEquals \ Contains \ TryGetCommonRootDirectory 
      List<DirectoryPathAbsolute> list1 = new List<DirectoryPathAbsolute>();
      List<DirectoryPathAbsolute> list2 = new List<DirectoryPathAbsolute>();
      list1.Add(new DirectoryPathAbsolute(@"C:\Dir1\Dir2"));
      list2.Add(new DirectoryPathAbsolute(@"c:\dir1\dir2"));
      list1.Add(new DirectoryPathAbsolute(@"C:\Dir1\Dir3\Dir4"));
      list2.Add(new DirectoryPathAbsolute(@"c:\dir1\dir3\dir4"));
      Debug.Assert(ListOfPathHelper.ListOfPathsEquals(list1, list2));
      Debug.Assert(ListOfPathHelper.Contains(list1, new DirectoryPathAbsolute(@"C:\Dir1\dir2")));
      ListOfPathHelper.TryGetCommonRootDirectory(list1, out directoryPathAbsolute1);
      Debug.Assert(directoryPathAbsolute1.Path == @"C:\Dir1");


      // List of path   GetListOfUniqueDirsAndUniqueFileNames
      List<FilePathAbsolute> list = new List<FilePathAbsolute>();
      list.Add(new FilePathAbsolute(@"E:\Dir1\Dir2\File1.txt"));
      list.Add(new FilePathAbsolute(@"E:\dir1\dir2\File2.txt"));
      list.Add(new FilePathAbsolute(@"E:\Dir1\Dir2\Dir3\file2.txt"));
      List<DirectoryPathAbsolute> listOfUniqueDirs;
      List<string> listOfUniqueFileNames;
      ListOfPathHelper.GetListOfUniqueDirsAndUniqueFileNames(list, out listOfUniqueDirs, out listOfUniqueFileNames);
      Debug.Assert(listOfUniqueDirs.Count == 2);
      Debug.Assert(listOfUniqueDirs[0].Path == @"E:\Dir1\Dir2");
      Debug.Assert(listOfUniqueDirs[1].Path == @"E:\Dir1\Dir2\Dir3");
      Debug.Assert(listOfUniqueFileNames.Count == 2);
      Debug.Assert(listOfUniqueFileNames[0] == "File1.txt");
      Debug.Assert(listOfUniqueFileNames[1] == "File2.txt");


      // Interaction with System.IO API
      filePathAbsolute1 = new FilePathAbsolute(
         System.Reflection.Assembly.GetExecutingAssembly().Location);
      Debug.Assert(filePathAbsolute1.Exists);
      System.IO.FileInfo fileInfo = filePathAbsolute1.FileInfo;

      directoryPathAbsolute1 = filePathAbsolute1.ParentDirectoryPath as DirectoryPathAbsolute;
      Debug.Assert(directoryPathAbsolute1.Exists);
      System.IO.DirectoryInfo directoryInfo = directoryPathAbsolute1.DirectoryInfo;

      List<DirectoryPathAbsolute> listSubDir = directoryPathAbsolute1.ChildrenDirectoriesPath;
      List<FilePathAbsolute> listSubFile = directoryPathAbsolute1.ChildrenFilesPath;

   }
예제 #32
0
 public void Test_GetChildWithName_Error9()
 {
     DirectoryPathRelative directoryPathRelative = new DirectoryPathRelative(@"..\Dir1\Dir2");
      directoryPathRelative.GetChildDirectoryWithName(String.Empty);
 }
예제 #33
0
        public void Test_PathEquality()
        {
            //
            // filePathRelative
            //
            FilePathRelative filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            FilePathRelative filePathRelative2 = new FilePathRelative(@"..\\dir1//file.TXT");

            Assert.IsTrue(filePathRelative1.Equals(filePathRelative2));
            Assert.IsTrue(filePathRelative1 == filePathRelative2);

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathRelative2 = new FilePathRelative(@".\Dir1\File.txt");
            Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
            Assert.IsFalse(filePathRelative1 == filePathRelative2);

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathRelative2 = new FilePathRelative(@"..\Dir1\Dir2\File.txt");
            Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
            Assert.IsFalse(filePathRelative1 == filePathRelative2);

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathRelative2 = new FilePathRelative(@"..\Dir1\File.tx");
            Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
            Assert.IsFalse(filePathRelative1 == filePathRelative2);

            //
            // filePathAbsolute
            //
            FilePathAbsolute filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            FilePathAbsolute filePathAbsolute2 = new FilePathAbsolute(@"C:\\dir1//file.TXT");

            Assert.IsTrue(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsTrue(filePathAbsolute1 == filePathAbsolute2);

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            filePathAbsolute2 = new FilePathAbsolute(@"D:\Dir1\File.txt");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\Dir2\File.txt");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\File.tx");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

            //
            // Mix between filePathAbsolute and filePathRelative
            //
            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathRelative1));
            Assert.IsFalse(filePathAbsolute1 == filePathRelative1);

            //
            // Mix between directoryPath and filePath
            //
            DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\File");

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File");
            Assert.IsFalse(directoryPathAbsolute1.Equals(filePathAbsolute1));
            Assert.IsFalse(filePathAbsolute1.Equals(directoryPathAbsolute1));
            Assert.IsFalse(filePathAbsolute1 == directoryPathAbsolute1);

            DirectoryPathRelative directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\File");

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File");
            Assert.IsFalse(directoryPathRelative1.Equals(filePathRelative1));
            Assert.IsFalse(filePathRelative1.Equals(directoryPathRelative1));
            Assert.IsFalse(filePathRelative1 == directoryPathRelative1);
        }
예제 #34
0
 public void Test_InnerSpecialDir_Error40()
 {
     BasePath path = new DirectoryPathRelative(@".\..\Dir1\..\..");
 }