Exemplo n.º 1
0
        public void CompareDirectoryHierarchy_FromDir_ToDir_ShouldShowParentAbove()
        {
            var parentPath = @"c:\foo\bar";
            var childPath  = @"c:\foo\bar\child\path";

            var parentWindowsPath = new PureWindowsPath(parentPath);
            var childWindowsPath  = new PureWindowsPath(childPath);

            Assert.True(childWindowsPath > parentWindowsPath);
        }
Exemplo n.º 2
0
        public void Addition_WithString_JoinsBoth()
        {
            var first = new PureWindowsPath(@"c:\users");
            const string second = @"nemec";
            var expected = new PureWindowsPath(@"C:\users\nemec");

            var actual = first + second;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void Addition_WithOtherPureWindowsPath_JoinsBoth()
        {
            var first    = new PureWindowsPath(@"c:\users");
            var second   = new PureWindowsPath(@"nemec");
            var expected = new PureWindowsPath(@"C:\users\nemec");

            var actual = first + second;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void CreatePath_WithEmptyPath_AllPartsAreNonNull()
        {
            var path = new PureWindowsPath("");

            Assert.NotNull(path.Drive);
            Assert.NotNull(path.Root);
            Assert.NotNull(path.Dirname);
            Assert.NotNull(path.Basename);
            Assert.NotNull(path.Extension);
            Assert.Empty(path.Parts.Where(p => p is null));
        }
Exemplo n.º 5
0
        public void GetAnchor_WithDriveAndNoRoot_ReturnsDrive()
        {
            // Arrange
            var path = new PureWindowsPath("c:some/share/foo.txt");

            // Act
            var actual = path.Anchor;

            // Assert
            Assert.Equal(@"c:", actual);
        }
Exemplo n.º 6
0
        public void GetRoot_WithDriveAndRoot_ReturnsRoot()
        {
            // Arrange
            var path = new PureWindowsPath("c:/some/share/foo.txt");

            // Act
            var actual = path.Root;

            // Assert
            Assert.Equal(@"\", actual);
        }
Exemplo n.º 7
0
        public void CreatePath_JoiningTwoLocalRoots_DoesNotChangeDrive()
        {
            // Arrange
            var paths = new[] { "c:/Windows", "/Program Files" };
            const string expected = @"c:/Program Files";

            // Act
            var path = new PureWindowsPath(paths);

            // Assert
            Assert.AreEqual(expected, path.ToPosix());
        }
Exemplo n.º 8
0
 /// <summary>
 /// Factory method to create a new <see cref="PurePath"/> instance
 /// based upon the current operating system.
 /// </summary>
 /// <param name="path"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public IPurePath Create(string path, PurePathFactoryOptions options)
 {
     IPurePath ret = null;
     switch (PlatformChooser.GetPlatform())
     {
         case Platform.Posix:
             ret = new PurePosixPath(path);
             break;
         case Platform.Windows:
             ret =  new PureWindowsPath(path);
             break;
     }
     return ApplyOptions(ret, options);
 }
Exemplo n.º 9
0
        public void GetDrive_WithUncShare_ReturnsShareName()
        {
            // Arrange
            var path = new PureWindowsPath("//some/share/foo.txt");

            // Act
            var actual = path.Drive;

            // Assert
            Assert.AreEqual(@"\\some\share", actual);
        }
Exemplo n.º 10
0
        public void RelativeTo_WithRootAndDrive_CalculatesRelativePath()
        {
            var expected = new PureWindowsPath(@"users\nemec");
            var root = new PureWindowsPath(@"C:\");
            var abs = new PureWindowsPath(@"C:\users\nemec");

            var actual = abs.RelativeTo(root);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void PathEquality_UsingWindowsPaths_ComparesCaseInsensitive()
        {
            // Arrange
            var first = new PureWindowsPath("foo");
            var second = new PureWindowsPath("FOO");

            // Act
            var actual = first == second;

            // Assert
            Assert.IsTrue(actual);
        }
Exemplo n.º 12
0
        public void GetRoot_WithUncShare_ReturnsShareRoot()
        {
            // Arrange
            var path = new PureWindowsPath("//some/share/foo.txt");

            // Act
            var actual = path.Root;

            // Assert
            Assert.AreEqual(@"\", actual);
        }
Exemplo n.º 13
0
        public void CreatePath_WithEmptyPath_AllPartsAreNonNull()
        {
            var path = new PureWindowsPath("");

            Assert.IsNotNull(path.Drive);
            Assert.IsNotNull(path.Root);
            Assert.IsNotNull(path.Dirname);
            Assert.IsNotNull(path.Basename);
            Assert.IsNotNull(path.Extension);
            CollectionAssert.AllItemsAreNotNull(path.Parts.ToList());
        }
Exemplo n.º 14
0
        public void CreatePath_WithCurrentDirectory_StoresAsDirname()
        {
            var path = new PureWindowsPath(".");

            Assert.AreEqual(".", path.Dirname);
        }
Exemplo n.º 15
0
        public void GetFilename_WithPathEndingInSlash_ReturnsLastPathComponent()
        {
            // POSIX spec drops the trailing slash

            // Arrange
            var path = new PureWindowsPath("some/path/");

            // Act
            var actual = path.Filename;

            // Assert
            Assert.AreEqual(@"path", actual);
        }
Exemplo n.º 16
0
        public void GetFilename_WithPathHavingFilename_ReturnsFilename()
        {
            // Arrange
            const string expected = "foo.txt";
            var path = new PureWindowsPath("some/path/foo.txt");

            // Act
            var actual = path.Filename;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 17
0
        public void CreatePath_WithFilename_StoresFilename()
        {
            var path = new PureWindowsPath("file.txt");

            Assert.AreEqual("file.txt", path.Filename);
        }
Exemplo n.º 18
0
        public void GetRoot_WithDriveAndNoRoot_ReturnsEmptyString()
        {
            // Arrange
            var path = new PureWindowsPath("c:some/share/foo.txt");

            // Act
            var actual = path.Root;

            // Assert
            Assert.AreEqual(@"", actual);
        }
Exemplo n.º 19
0
        public void GetAnchor_WithNoDriveAndRoot_ReturnsRoot()
        {
            // Arrange
            var path = new PureWindowsPath("/some/share/foo.txt");

            // Act
            var actual = path.Anchor;

            // Assert
            Assert.AreEqual(@"\", actual);
        }
Exemplo n.º 20
0
        public void IsAbsolute_WithDriveAndNoRoot_ReturnsFalse()
        {
            // Arrange
            var path = new PureWindowsPath("c:some/share/foo.txt");

            // Act
            var actual = path.IsAbsolute();

            // Assert
            Assert.AreEqual(false, actual);
        }
Exemplo n.º 21
0
        public void GetAnchor_WithRelativePath_ReturnsEmptyString()
        {
            // Arrange
            var path = new PureWindowsPath("some/share/foo.txt");

            // Act
            var actual = path.Anchor;

            // Assert
            Assert.AreEqual(@"", actual);
        }
Exemplo n.º 22
0
        public void RelativeTo_WithCaseInsensitivePathAndDifferentCasing_CalculatesRelativePath()
        {
            var expected = new PureWindowsPath(@"nemec\downloads");
            var root = new PureWindowsPath(@"C:\users");
            var abs = new PureWindowsPath(@"C:\USERS\nemec\downloads");

            var actual = abs.RelativeTo(root);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 23
0
        public void GetDirname_WithDriveAndFilenameButNoBasename_ReturnsEmptyString()
        {
            // Arrange
            const string expected = "";
            var path = new PureWindowsPath("d:foo.txt");

            // Act
            var actual = path.Dirname;

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        public void XmlDeserialize_WithPathAsStringElement_DeserializesIntoType()
        {
            const string pathXml = @"<XmlDeserialize><Folder>c:\users\nemec</Folder></XmlDeserialize>";
            var obj = (XmlDeserialize)new XmlSerializer(typeof(XmlDeserialize))
                .Deserialize(new StringReader(pathXml));
            var expected = new PureWindowsPath(@"c:\users\nemec");

            Assert.AreEqual(expected, obj.Folder);
        }
Exemplo n.º 25
0
        public void GetDrive_WithDrive_ReturnsDriveName()
        {
            // Arrange
            var path = new PureWindowsPath("c:/Program Files/");

            // Act
            var actual = path.Drive;

            // Assert
            Assert.AreEqual("c:", actual);
        }
Exemplo n.º 26
0
        public void CreatePath_WhereSecondPathContainsDriveButNoRoot_ChangesDriveAndHasNoRoot()
        {
            // Arrange
            var expected = new PureWindowsPath(@"d:bar");
            var actual = new PureWindowsPath(@"c:\windows", @"d:bar");

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 27
0
        public void GetDrive_WithNoDrive_ReturnsEmptyString()
        {
            // Arrange
            var path = new PureWindowsPath("/Program Files/");

            // Act
            var actual = path.Drive;

            // Assert
            Assert.AreEqual(String.Empty, actual);
        }