public void MoveFile(FakeFile fakeFile, FilePath destination) { // Copy the file to the new location. CopyFile(fakeFile, destination, false); // Delete the original file. fakeFile.Delete(); }
public void CreateFile(FakeFile file) { // Get the directory that the file exists in. var directory = FindDirectory(file.Path.GetDirectory()); if (directory == null) { file.Exists = false; throw new DirectoryNotFoundException(string.Format("Could not find a part of the path '{0}'.", file.Path.FullPath)); } if (!directory.Content.Files.ContainsKey(file.Path)) { // Add the file to the directory. file.Exists = true; directory.Content.Add(file); } }
public void DeleteFile(FakeFile file) { if (!file.Exists) { throw new FileNotFoundException("File does not exist.", file.Path.FullPath); } // Find the directory. var directory = FindDirectory(file.Path.GetDirectory()); // Remove the file from the directory. directory.Content.Remove(file); // Reset all properties. file.Exists = false; file.Content = null; file.ContentLength = 0; }
public void CopyFile(FakeFile file, FilePath destination, bool overwrite) { if (!file.Exists) { throw new FileNotFoundException("File do not exist."); } // Already exists? var destinationFile = FindFile(destination); if (destinationFile != null) { if (!overwrite) { const string format = "{0} exists and overwrite is false."; var message = string.Format(format, destination.FullPath); throw new IOException(message); } } // Directory exists? var directory = FindDirectory(destination.GetDirectory()); if (directory == null || !directory.Exists) { throw new DirectoryNotFoundException("The destination path {0} do not exist."); } // Make sure the file exist. if (destinationFile == null) { destinationFile = new FakeFile(this, destination); } // Copy the data from the original file to the destination. using (var input = file.OpenRead()) using (var output = destinationFile.OpenWrite()) { input.CopyTo(output); } }
public FakeFileStream(FakeFile file) { _file = file; _position = 0; }
public void Remove(FakeFile file) { _files.Remove(file.Path); }
public void Add(FakeFile file) { _files.Add(file.Path, file); }