public override FileProperties GetFileProperties(string path) { MockFile file = this.RootDirectory.FindFile(path); if (file != null) { return(file.FileProperties); } else { return(FileProperties.DefaultFile); } }
public override SafeHandle OpenFile(string path, FileMode fileMode, FileAccess fileAccess, FileAttributes attributes, FileShare shareMode) { if (fileMode == FileMode.Create) { MockFile newFile = this.RootDirectory.CreateFile(path); FileProperties newProperties = new FileProperties( attributes, newFile.FileProperties.CreationTimeUTC, newFile.FileProperties.LastAccessTimeUTC, newFile.FileProperties.LastWriteTimeUTC, newFile.FileProperties.Length); newFile.FileProperties = newProperties; } return(new MockSafeHandle(path, this.OpenFileStream(path, fileMode, fileAccess, shareMode))); }
public void AddFile(MockFile file, string path) { string parentPath = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)); MockDirectory parentDirectory = this.FindDirectory(parentPath); if (parentDirectory == null) { throw new IOException(); } MockFile existingFileAtPath = parentDirectory.FindFile(path); existingFileAtPath.ShouldBeNull(); parentDirectory.Files.Add(file.FullName, file); }
public override void DeleteFile(string path) { if (this.DeleteFileThrowsException) { throw new IOException("Exception when deleting file"); } MockFile file = this.RootDirectory.FindFile(path); if (file == null && !this.DeleteNonExistentFileThrowsException) { return; } file.ShouldNotBeNull(); this.RootDirectory.RemoveFile(path); }
public override Stream OpenFileStream(string path, FileMode fileMode, FileAccess fileAccess, NativeMethods.FileAttributes attributes, FileShare shareMode) { MockFile file = this.RootDirectory.FindFile(path); if (fileMode == FileMode.OpenOrCreate) { if (file == null) { return(this.CreateAndOpenFileStream(path)); } } else { file.ShouldNotBeNull(); } return(file.GetContentStream()); }
public void AddOrOverwriteFile(MockFile file, string path) { string parentPath = path.Substring(0, path.LastIndexOf(GVFSConstants.PathSeparator)); MockDirectory parentDirectory = this.FindDirectory(parentPath); if (parentDirectory == null) { throw new IOException(); } MockFile existingFileAtPath = parentDirectory.FindFile(path); if (existingFileAtPath != null) { parentDirectory.Files.Remove(path); } parentDirectory.Files.Add(file.FullName, file); }
public override void MoveAndOverwriteFile(string sourcePath, string destinationPath) { if (sourcePath == null || destinationPath == null) { throw new ArgumentNullException(); } MockFile sourceFile = this.RootDirectory.FindFile(sourcePath); MockFile destinationFile = this.RootDirectory.FindFile(destinationPath); if (sourceFile == null) { throw new FileNotFoundException(); } if (destinationFile != null) { this.RootDirectory.RemoveFile(destinationPath); } this.WriteAllText(destinationPath, this.ReadAllText(sourcePath)); this.RootDirectory.RemoveFile(sourcePath); }
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 override void WriteAllText(string path, string contents) { MockFile file = new MockFile(path, contents); this.RootDirectory.AddOrOverwriteFile(file, path); }