protected override bool CheckParameterValues(IOutputter outputter) { if (GetParameters().Count > 0) { string dirPath = GetParameters()[0]; FileSystemItem fs = Drive.GetItemFromPath(dirPath); if (fs == null) { outputter.PrintLine("File Not Found"); return(false); } if (fs.IsDirectory() == false) { dirToPrint = fs.Parent; } else { dirToPrint = (Directory)fs; } } else { dirToPrint = Drive.CurrentDirectory; } return(true); }
public void Content_Subdirectory_ParentIsSetCorrectly() { FileSystemItem item = rootDir.Content.ElementAt(0); FileSystemItem parent = item.Parent; Assert.IsTrue(parent.IsDirectory()); Assert.AreSame(this.rootDir, parent); }
public void Content_Subdirectory_Element0HasCorrectName() { FileSystemItem item = rootDir.Content.ElementAt(0); Assert.IsTrue(item.IsDirectory()); Assert.AreEqual(subDir1.Name, item.Name); Assert.AreSame(this.subDir1, item); }
public static Directory GetDirectory(IDrive drive, string directoryPath, string directoryName) { FileSystemItem fileSystemItem = drive.GetItemFromPath(directoryPath); Assert.IsNotNull(fileSystemItem); Assert.AreEqual(directoryName, fileSystemItem.Name); Assert.IsTrue(fileSystemItem.IsDirectory()); return((Directory)fileSystemItem); }
public static File GetFile(IDrive drive, string filePath, string fileName) { FileSystemItem fileSystemItem = drive.GetItemFromPath(filePath + "\\" + fileName); Assert.IsNotNull(fileSystemItem); Assert.AreEqual(fileName, fileSystemItem.Name); Assert.IsFalse(fileSystemItem.IsDirectory()); return((File)fileSystemItem); }
public override void Execute(IOutputter outputter) { bool retVal = false; // cd without parameters if (newDirectoryName == null) { outputter.PrintLine(Drive.CurrentDirectory.Path); return; } // cd with parameters: Check if passed directory is valid before change to this directory FileSystemItem newDir = Drive.GetItemFromPath(newDirectoryName); if (newDir == null) { outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED); return; } if (newDir.IsDirectory() == false) { outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED); return; } if (Drive.GetItemFromPath(newDir.Path) != newDir) { outputter.PrintLine("Path not in drive " + Drive.DriveName); return; } if (newDir.IsDirectory()) { retVal = Drive.ChangeCurrentDirectory((Directory)newDir); } if (retVal == false) { outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED); } }
private Directory CheckAndPreparePathParameter(string pathName, IOutputter outputter) { FileSystemItem fsi = Drive.GetItemFromPath(pathName); if (fsi == null) { outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED); return(null); } if (!fsi.IsDirectory()) { return(fsi.Parent); } if (fsi.IsDirectory()) { outputter.PrintLine(ACCESS_DENIED); return(null); } return((Directory)fsi); }
public void testSingleCharacterDirectories() { Assert.IsTrue(rootDir.GetNumberOfContainedDirectories() == 2); var newDir = new Directory("N"); rootDir.Add(newDir); Assert.IsTrue(rootDir.GetNumberOfContainedDirectories() == 3); FileSystemItem item = drive.GetItemFromPath(rootDir.Path + "\\N"); Assert.IsNotNull(item); Assert.IsTrue(item.IsDirectory()); Assert.AreSame(item, newDir); }
private static Directory ExtractAndCheckIfValidDirectory(string destinationDirectoryName, IDrive drive, IOutputter outputter) { FileSystemItem tempDestinationDirectory = drive.GetItemFromPath(destinationDirectoryName); if (tempDestinationDirectory == null) { outputter.PrintLine(SYSTEM_CANNOT_FIND_THE_PATH_SPECIFIED); return(null); } if (!tempDestinationDirectory.IsDirectory()) { outputter.PrintLine(DESTINATION_IS_FILE); return(null); } return((Directory)tempDestinationDirectory); }
public static Directory ExtractAndCheckIfValidDirectory(string destinationDirectoryName, IDrive drive, IOutputter outputter) { FileSystemItem tempDestinationDirectory = drive.GetItemFromPath(destinationDirectoryName); if (tempDestinationDirectory == null) { outputter.PrintLine(NO_IS_FILE + destinationDirectoryName); return(null); } if (!tempDestinationDirectory.IsDirectory()) { outputter.PrintLine(DESTINATION_IS_FILE); return(null); } return((Directory)tempDestinationDirectory); }
public void testSubDirectory() { List <FileSystemItem> content = rootDir.Content; Assert.IsTrue(content != null); Assert.IsTrue(content.Count == 2); FileSystemItem item = content[0]; Assert.IsTrue(item.IsDirectory()); Assert.IsTrue(item.Name.CompareTo(subDir1.Name) == 0); FileSystemItem parent = item.Parent; Assert.IsTrue(parent.IsDirectory()); Assert.AreSame(parent, rootDir); Assert.IsTrue(parent.Parent == null); string path = item.Path; Assert.IsTrue(path.CompareTo(rootDir.Name + "\\" + subDir1.Name) == 0); }