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); }
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); }
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); }
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)); }
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); }
public void GetRoot_WithDriveAndRoot_ReturnsRoot() { // Arrange var path = new PureWindowsPath("c:/some/share/foo.txt"); // Act var actual = path.Root; // Assert Assert.Equal(@"\", actual); }
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()); }
/// <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); }
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); }
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); }
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); }
public void GetRoot_WithUncShare_ReturnsShareRoot() { // Arrange var path = new PureWindowsPath("//some/share/foo.txt"); // Act var actual = path.Root; // Assert Assert.AreEqual(@"\", actual); }
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()); }
public void CreatePath_WithCurrentDirectory_StoresAsDirname() { var path = new PureWindowsPath("."); Assert.AreEqual(".", path.Dirname); }
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); }
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); }
public void CreatePath_WithFilename_StoresFilename() { var path = new PureWindowsPath("file.txt"); Assert.AreEqual("file.txt", path.Filename); }
public void GetRoot_WithDriveAndNoRoot_ReturnsEmptyString() { // Arrange var path = new PureWindowsPath("c:some/share/foo.txt"); // Act var actual = path.Root; // Assert Assert.AreEqual(@"", actual); }
public void GetAnchor_WithNoDriveAndRoot_ReturnsRoot() { // Arrange var path = new PureWindowsPath("/some/share/foo.txt"); // Act var actual = path.Anchor; // Assert Assert.AreEqual(@"\", actual); }
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); }
public void GetAnchor_WithRelativePath_ReturnsEmptyString() { // Arrange var path = new PureWindowsPath("some/share/foo.txt"); // Act var actual = path.Anchor; // Assert Assert.AreEqual(@"", actual); }
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); }
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); }
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); }
public void GetDrive_WithDrive_ReturnsDriveName() { // Arrange var path = new PureWindowsPath("c:/Program Files/"); // Act var actual = path.Drive; // Assert Assert.AreEqual("c:", actual); }
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); }
public void GetDrive_WithNoDrive_ReturnsEmptyString() { // Arrange var path = new PureWindowsPath("/Program Files/"); // Act var actual = path.Drive; // Assert Assert.AreEqual(String.Empty, actual); }