public override void Copy(string sourceFileName, string destFileName, bool overwrite) { ValidateParameter(sourceFileName, "sourceFileName"); ValidateParameter(destFileName, "destFileName"); var directoryNameOfDestination = mockPath.GetDirectoryName(destFileName); if (!mockFileDataAccessor.Directory.Exists(directoryNameOfDestination)) { throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, "Could not find a part of the path '{0}'.", destFileName)); } var fileExists = mockFileDataAccessor.FileExists(destFileName); if (fileExists) { if (!overwrite) { throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName)); } mockFileDataAccessor.RemoveFile(destFileName); } var sourceFile = mockFileDataAccessor.GetFile(sourceFileName); mockFileDataAccessor.AddFile(destFileName, sourceFile); }
public override void Move(string sourceFileName, string destFileName) { var sourceFile = mockFileDataAccessor.GetFile(sourceFileName); mockFileDataAccessor.AddFile(destFileName, new MockFileData(sourceFile.Contents)); mockFileDataAccessor.RemoveFile(sourceFileName); }
public override void Copy(string sourceFileName, string destFileName, bool overwrite) { if (overwrite) { if (mockFileDataAccessor.FileExists(destFileName)) { var sourceFile = mockFileDataAccessor.GetFile(sourceFileName); mockFileDataAccessor.RemoveFile(destFileName); mockFileDataAccessor.AddFile(destFileName, sourceFile); return; } } Copy(sourceFileName, destFileName); }
public override void Delete(string path, bool recursive) { path = mockFileDataAccessor.Path.GetFullPath(path).TrimSlashes(); var stringOps = mockFileDataAccessor.StringOperations; var pathWithDirectorySeparatorChar = $"{path}{Path.DirectorySeparatorChar}"; var affectedPaths = mockFileDataAccessor .AllPaths .Where(p => stringOps.Equals(p, path) || stringOps.StartsWith(p, pathWithDirectorySeparatorChar)) .ToList(); if (!affectedPaths.Any()) { throw new DirectoryNotFoundException(path + " does not exist or could not be found."); } if (!recursive && affectedPaths.Count > 1) { throw new IOException("The directory specified by " + path + " is read-only, or recursive is false and " + path + " is not an empty directory."); } foreach (var affectedPath in affectedPaths) { mockFileDataAccessor.RemoveFile(affectedPath); } }
public override void Copy(string sourceFileName, string destFileName, bool overwrite) { if (sourceFileName == null) { throw new ArgumentNullException(nameof(sourceFileName), StringResources.Manager.GetString("FILENAME_CANNOT_BE_NULL")); } if (destFileName == null) { throw new ArgumentNullException(nameof(destFileName), StringResources.Manager.GetString("FILENAME_CANNOT_BE_NULL")); } mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, "sourceFileName"); mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, "destFileName"); if (!Exists(sourceFileName)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_FILE_EXCEPTION"), sourceFileName)); } var directoryNameOfDestination = mockPath.GetDirectoryName(destFileName); if (!mockFileDataAccessor.Directory.Exists(directoryNameOfDestination)) { throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_PART_OF_PATH_EXCEPTION"), destFileName)); } var fileExists = mockFileDataAccessor.FileExists(destFileName); if (fileExists) { if (!overwrite) { throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName)); } mockFileDataAccessor.RemoveFile(destFileName); } var sourceFileData = mockFileDataAccessor.GetFile(sourceFileName); mockFileDataAccessor.AddFile(destFileName, new MockFileData(sourceFileData)); }
public override void Copy(string sourceFileName, string destFileName, bool overwrite) { //This is the order that checks are executed in MSCORLIB. if (sourceFileName == null) { throw new ArgumentNullException("sourceFileName", Properties.Resources.FILENAME_CANNOT_BE_NULL); } if (destFileName == null) { throw new ArgumentNullException("destFileName", Properties.Resources.FILENAME_CANNOT_BE_NULL); } mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, "sourceFileName"); mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, "destFileName"); if (!Exists(sourceFileName)) { throw new FileNotFoundException(); } var directoryNameOfDestination = mockPath.GetDirectoryName(destFileName); if (!mockFileDataAccessor.Directory.Exists(directoryNameOfDestination)) { throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.COULD_NOT_FIND_PART_OF_PATH_EXCEPTION, destFileName)); } var fileExists = mockFileDataAccessor.FileExists(destFileName); if (fileExists) { if (!overwrite) { throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName)); } mockFileDataAccessor.RemoveFile(destFileName); } var sourceFile = mockFileDataAccessor.GetFile(sourceFileName); mockFileDataAccessor.AddFile(destFileName, sourceFile); }
private void OnClose() { if (options.HasFlag(FileOptions.DeleteOnClose) && mockFileDataAccessor.FileExists(path)) { mockFileDataAccessor.RemoveFile(path); } if (options.HasFlag(FileOptions.Encrypted) && mockFileDataAccessor.FileExists(path)) { mockFileDataAccessor.FileInfo.FromFileName(path).Encrypt(); } }
public override void Copy(string sourceFileName, string destFileName, bool overwrite) { if (sourceFileName == null) { throw CommonExceptions.FilenameCannotBeNull(nameof(sourceFileName)); } if (destFileName == null) { throw CommonExceptions.FilenameCannotBeNull(nameof(destFileName)); } mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, nameof(sourceFileName)); mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, nameof(destFileName)); if (!Exists(sourceFileName)) { throw CommonExceptions.FileNotFound(sourceFileName); } VerifyDirectoryExists(destFileName); var fileExists = mockFileDataAccessor.FileExists(destFileName); if (fileExists) { if (!overwrite) { throw new IOException(string.Format(CultureInfo.InvariantCulture, "The file {0} already exists.", destFileName)); } mockFileDataAccessor.RemoveFile(destFileName); } var sourceFileData = mockFileDataAccessor.GetFile(sourceFileName); sourceFileData.CheckFileAccess(sourceFileName, FileAccess.Read); mockFileDataAccessor.AddFile(destFileName, new MockFileData(sourceFileData)); }
public override void Copy(string sourceFileName, string destFileName, bool overwrite) { if (sourceFileName == null) { throw new ArgumentNullException(nameof(sourceFileName), Properties.Resources.FILENAME_CANNOT_BE_NULL); } if (destFileName == null) { throw new ArgumentNullException(nameof(destFileName), Properties.Resources.FILENAME_CANNOT_BE_NULL); } _mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(sourceFileName, nameof(sourceFileName)); _mockFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(destFileName, nameof(destFileName)); string directoryNameOfDestination = _mockPath.GetDirectoryName(destFileName); if (!_mockFileDataAccessor.Directory.Exists(directoryNameOfDestination)) { throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.COULD_NOT_FIND_PART_OF_PATH_EXCEPTION, destFileName)); } bool fileExists = _mockFileDataAccessor.FileExists(destFileName); if (fileExists) { if (!overwrite) { throw new IOException($"The file {destFileName} already exists."); } _mockFileDataAccessor.RemoveFile(destFileName); } MockFileData sourceFile = _mockFileDataAccessor.GetFile(sourceFileName); _mockFileDataAccessor.AddFile(destFileName, sourceFile); }
private void InternalFlush() { if (mockFileDataAccessor.FileExists(path)) { mockFileDataAccessor.RemoveFile(path); } /* reset back to the beginning .. */ base.Seek(0, SeekOrigin.Begin); /* .. read everything out */ var data = new byte[base.Length]; base.Read(data, 0, (int)base.Length); /* .. put it in the mock system */ mockFileDataAccessor.AddFile(path, new MockFileData(data)); }
public override void Delete(string path, bool recursive) { path = EnsurePathEndsWithDirectorySeparator(mockFileDataAccessor.Path.GetFullPath(path)); var affectedPaths = mockFileDataAccessor .AllPaths .Where(p => p.StartsWith(path, StringComparison.OrdinalIgnoreCase)) .ToList(); if (!affectedPaths.Any()) { throw new DirectoryNotFoundException(path + " does not exist or could not be found."); } if (!recursive && affectedPaths.Count > 1) { throw new IOException("The directory specified by " + path + " is read-only, or recursive is false and " + path + " is not an empty directory."); } foreach (var affectedPath in affectedPaths) { mockFileDataAccessor.RemoveFile(affectedPath); } }
public override void Delete() { mockFileSystem.RemoveFile(path); }