private void AddDirectory(MockDirectory directory) { if (this.Directories.ContainsKey(directory.FullName)) { MockDirectory oldDirectory = this.Directories[directory.FullName]; foreach (MockFile newFile in directory.Files.Values) { newFile.FullName = Path.Combine(oldDirectory.FullName, newFile.Name); oldDirectory.AddOrOverwriteFile(newFile, newFile.FullName); } foreach (MockDirectory newDirectory in directory.Directories.Values) { newDirectory.FullName = Path.Combine(oldDirectory.FullName, newDirectory.Name); this.AddDirectory(newDirectory); } } else { this.Directories.Add(directory.FullName, directory); } }
public MockFile CreateFile(string path, string contents, bool createDirectories = false) { string parentPath = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)); MockDirectory parentDirectory = this.FindDirectory(parentPath); if (createDirectories) { if (parentDirectory == null) { parentDirectory = this.CreateDirectory(parentPath); } } else { parentDirectory.ShouldNotBeNull(); } MockFile newFile = new MockFile(path, contents); parentDirectory.Files.Add(newFile.FullName, newFile); return(newFile); }
public MockFileSystem(MockDirectory rootDirectory) { this.RootDirectory = rootDirectory; this.DeleteNonExistentFileThrowsException = true; }
public MockFileSystem(MockDirectory rootDirectory) { this.RootDirectory = rootDirectory; }
public MockFileSystem(MockDirectory rootDirectory) { this.RootDirectory = rootDirectory; this.DeleteNonExistentFileThrowsException = true; this.TryCreateOrUpdateDirectoryToAdminModifyPermissionsShouldSucceed = true; }
private bool TryGetDirectoryAndParent(string path, out MockDirectory directory, out MockDirectory parentDirectory) { if (this.Directories.TryGetValue(path, out directory)) { parentDirectory = this; return(true); } else { string parentPath = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)); parentDirectory = this.FindDirectory(parentPath); if (parentDirectory != null) { foreach (MockDirectory subDirectory in this.Directories.Values) { directory = subDirectory.FindDirectory(path); if (directory != null) { return(true); } } } } directory = null; parentDirectory = null; return(false); }
public void RemoveDirectory(MockDirectory directory) { this.Directories.ContainsKey(directory.FullName).ShouldEqual(true); this.Directories.Remove(directory.FullName); }
public MockFileSystem(MockDirectory rootDirectory) { this.RootDirectory = rootDirectory; this.DeleteNonExistentFileThrowsException = true; this.TryCreateDirectoryWithAdminOnlyModifyShouldSucceed = true; }