public IFile GetFile(string path) { try { path = path.Replace("/", "\\"); string directoryPath = path.Substring(0, path.LastIndexOf(@"\")); string filename = path.Substring(directoryPath.Length + 1); MockDirectory directory = (MockDirectory)GetDirectory(directoryPath); if (directory.Exists) { List <IFile> files = directory.GetFiles(filename); if (files.Count != 0) { return(files[0]); } } // if the file is not found in the repository then return a stub for a non-existent file return(new MockFile(directory, filename)); } catch (Exception) { throw new InvalidOperationException("The format of the path supplied is invalid: " + path); } }
public void WriteBinary(byte[] data) { if (_parent == null) { throw new DirectoryNotFoundException("Parent directory is null."); } LastAccessTimeUtc = TimeService.Current.Now; LastWriteTimeUtc = TimeService.Current.Now; _stream = new MockStream(); _stream.Open(); _stream.Write(data, 0, data.Length); if (_parent.GetFiles(Name).Count == 0) { _parent.AddFile(this); } }