예제 #1
0
        public void Initialize_with_New_Invalid_Directory_Path_Initializes_With_Directory_Properties()
        {
            string   originalPath = @"C:\Foo\Bar\Moo\Nar";
            FilePath filePath     = new FilePath(originalPath);

            Assert.AreEqual(originalPath, filePath.Directory);
            Assert.IsEmpty(filePath.FileName);
            Assert.IsEmpty(filePath.FileExtension);
            Assert.IsEmpty(filePath.FileNameWithExtension);
            Assert.IsEmpty(filePath.PathChildStub);
            Assert.AreEqual(originalPath, filePath.Path());

            // Check empty, valid, and invalid relative paths
            Assert.AreEqual("", filePath.Path(originalPath));

            string defaultBasePath    = Application.StartupPath;
            string returnedTargetPath = originalPath;

            PathLibrary.RelativePath(ref returnedTargetPath, basePath: defaultBasePath);
            Assert.AreEqual(returnedTargetPath, filePath.Path(""));         // By default gives relative path to calling application if no default base path is supplied

            Assert.AreEqual(@"Moo\Nar", filePath.Path(@"C:\Foo\Bar"));
            Assert.AreEqual(originalPath, filePath.Path(@"D:\Foo\Bar")); // Does not handle different drive letters & defaults to assembly plath

            Assert.IsTrue(filePath.IsDirectoryOnly);
            Assert.IsFalse(filePath.IsFileNameOnly);
            Assert.IsFalse(filePath.IsValidPath);

            Assert.IsFalse(filePath.IsSelected);
            filePath.IsSelected = true;
            Assert.IsTrue(filePath.IsSelected);
        }
예제 #2
0
        public void Initialize_with_New_Path_As_Matching_No_Extension_File_Type_Initializes_With_File_Properties(ePathType pathType)
        {
            string fileExtension     = "";
            string fileName          = "Bar";
            string originalDirectory = @"C:\Foo";
            string originalPath      = System.IO.Path.Combine(originalDirectory, fileName);

            FilePath filePath = new FilePath(originalPath, pathType);

            Assert.AreEqual(originalDirectory, filePath.Directory);
            Assert.AreEqual(fileName, filePath.FileName);
            Assert.AreEqual(fileExtension, filePath.FileExtension);
            Assert.AreEqual(fileName + "." + fileExtension, filePath.FileNameWithExtension);
            Assert.IsEmpty(filePath.PathChildStub);
            Assert.AreEqual(originalPath, filePath.Path());

            // Check empty, valid, and invalid relative paths
            Assert.AreEqual(fileName + "." + fileExtension, filePath.Path(originalDirectory));

            string defaultBasePath    = Application.StartupPath;
            string returnedTargetPath = originalPath;

            PathLibrary.RelativePath(ref returnedTargetPath, basePath: defaultBasePath);
            Assert.AreEqual(returnedTargetPath, filePath.Path(""));         // By default gives relative path to calling application if no default base path is supplied

            string assemblyPathWithoutDrive = originalPath.Substring(3);

            Assert.AreEqual(@"..\..\" + assemblyPathWithoutDrive, filePath.Path(@"C:\Foo\Bar"));
            Assert.AreEqual(originalPath, filePath.Path(@"D:\Foo\Bar")); // Does not handle different drive letters & defaults to assembly plath

            Assert.IsFalse(filePath.IsDirectoryOnly);
            Assert.IsFalse(filePath.IsFileNameOnly);
            Assert.IsTrue(filePath.IsValidPath);

            Assert.IsFalse(filePath.IsSelected);
            filePath.IsSelected = true;
            Assert.IsTrue(filePath.IsSelected);
        }