public override Stream OpenFileStream(string path, FileMode fileMode, FileAccess fileAccess, FileShare shareMode, FileOptions options, bool flushesToDisk) { MockFile file = this.RootDirectory.FindFile(path); if (fileMode == FileMode.Create) { if (file != null) { this.RootDirectory.RemoveFile(path); } return(this.CreateAndOpenFileStream(path)); } if (fileMode == FileMode.OpenOrCreate) { if (file == null) { return(this.CreateAndOpenFileStream(path)); } } else { file.ShouldNotBeNull(); } return(file.GetContentStream()); }
private Stream CreateAndOpenFileStream(string path) { MockFile file = this.RootDirectory.CreateFile(path); file.ShouldNotBeNull(); return(this.OpenFileStream(path, FileMode.Open, (FileAccess)NativeMethods.FileAccess.FILE_GENERIC_READ, FileShare.Read, callFlushFileBuffers: false)); }
public override void DeleteFile(string path) { MockFile file = this.RootDirectory.FindFile(path); file.ShouldNotBeNull(); this.RootDirectory.RemoveFile(path); }
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()); }