Example #1
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);
        }
Example #2
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());
        }
Example #3
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);
 }
Example #4
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);
        }
Example #5
0
        public void GetRoot_WithUncShare_ReturnsShareRoot()
        {
            // Arrange
            var path = new PureWindowsPath("//some/share/foo.txt");

            // Act
            var actual = path.Root;

            // Assert
            Assert.AreEqual(@"\", actual);
        }
Example #6
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);
        }
Example #7
0
        public void CreatePath_WithCurrentDirectory_StoresAsDirname()
        {
            var path = new PureWindowsPath(".");

            Assert.AreEqual(".", path.Dirname);
        }
Example #8
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);
        }
Example #9
0
        public void GetDrive_WithNoDrive_ReturnsEmptyString()
        {
            // Arrange
            var path = new PureWindowsPath("/Program Files/");

            // Act
            var actual = path.Drive;

            // Assert
            Assert.AreEqual(String.Empty, actual);
        }
Example #10
0
        public void GetDrive_WithDrive_ReturnsDriveName()
        {
            // Arrange
            var path = new PureWindowsPath("c:/Program Files/");

            // Act
            var actual = path.Drive;

            // Assert
            Assert.AreEqual("c:", actual);
        }
Example #11
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);
        }
Example #12
0
        public void GetAnchor_WithRelativePath_ReturnsEmptyString()
        {
            // Arrange
            var path = new PureWindowsPath("some/share/foo.txt");

            // Act
            var actual = path.Anchor;

            // Assert
            Assert.AreEqual(@"", actual);
        }
Example #13
0
        public void GetAnchor_WithNoDriveAndRoot_ReturnsRoot()
        {
            // Arrange
            var path = new PureWindowsPath("/some/share/foo.txt");

            // Act
            var actual = path.Anchor;

            // Assert
            Assert.AreEqual(@"\", actual);
        }
Example #14
0
        public void CreatePath_WithFilename_StoresFilename()
        {
            var path = new PureWindowsPath("file.txt");

            Assert.AreEqual("file.txt", path.Filename);
        }
Example #15
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());
        }
Example #16
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);
        }
Example #17
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);
        }
Example #18
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);
        }
Example #19
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);
        }
Example #20
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);
        }
Example #21
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);
        }
Example #22
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);
        }