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()); }
public override byte[] ReadAllBytes(string path) { MockFile file = this.RootDirectory.FindFile(path); using (Stream s = file.GetContentStream()) { int count = (int)s.Length; int pos = 0; byte[] result = new byte[count]; while (count > 0) { int n = s.Read(result, pos, count); if (n == 0) { throw new IOException("Unexpected end of stream"); } pos += n; count -= n; } return(result); } }
public override string ReadAllText(string path) { MockFile file = this.RootDirectory.FindFile(path); using (StreamReader reader = new StreamReader(file.GetContentStream())) { return(reader.ReadToEnd()); } }
public override IEnumerable <string> ReadLines(string path) { MockFile file = this.RootDirectory.FindFile(path); using (StreamReader reader = new StreamReader(file.GetContentStream())) { while (!reader.EndOfStream) { yield return(reader.ReadLine()); } } }
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()); }