public override void Move(string sourceDirName, string destDirName) { var fullSourcePath = mockFileDataAccessor.Path.GetFullPath(sourceDirName).TrimSlashes(); var fullDestPath = mockFileDataAccessor.Path.GetFullPath(destDirName).TrimSlashes(); if (string.Equals(fullSourcePath, fullDestPath, StringComparison.OrdinalIgnoreCase)) { throw new IOException("Source and destination path must be different."); } var sourceRoot = mockFileDataAccessor.Path.GetPathRoot(fullSourcePath); var destinationRoot = mockFileDataAccessor.Path.GetPathRoot(fullDestPath); if (!string.Equals(sourceRoot, destinationRoot, StringComparison.OrdinalIgnoreCase)) { throw new IOException("Source and destination path must have identical roots. Move will not work across volumes."); } if (!mockFileDataAccessor.Directory.Exists(fullSourcePath)) { throw new DirectoryNotFoundException($"Could not find a part of the path '{sourceDirName}'."); } if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath)) { throw new IOException($"Cannot create '{fullDestPath}' because a file or directory with the same name already exists."); } mockFileDataAccessor.MoveDirectory(fullSourcePath, fullDestPath); }
public override void Move(string sourceDirName, string destDirName) { var fullSourcePath = mockFileDataAccessor.Path.GetFullPath(sourceDirName).TrimSlashes(); var fullDestPath = mockFileDataAccessor.Path.GetFullPath(destDirName).TrimSlashes(); if (mockFileDataAccessor.StringOperations.Equals(fullSourcePath, fullDestPath)) { throw new IOException("Source and destination path must be different."); } //if we're moving a file, not a directory, call the appropriate file moving function. var fileData = mockFileDataAccessor.GetFile(fullSourcePath); if (fileData?.Attributes.HasFlag(FileAttributes.Directory) == false) { mockFileDataAccessor.File.Move(fullSourcePath, fullDestPath); return; } var sourceRoot = mockFileDataAccessor.Path.GetPathRoot(fullSourcePath); var destinationRoot = mockFileDataAccessor.Path.GetPathRoot(fullDestPath); if (!mockFileDataAccessor.StringOperations.Equals(sourceRoot, destinationRoot)) { throw new IOException("Source and destination path must have identical roots. Move will not work across volumes."); } if (!mockFileDataAccessor.Directory.Exists(fullSourcePath)) { throw new DirectoryNotFoundException($"Could not find a part of the path '{sourceDirName}'."); } if (!mockFileDataAccessor.Directory.GetParent(fullDestPath).Exists) { throw new DirectoryNotFoundException($"Could not find a part of the path."); } if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath)) { throw new IOException($"Cannot create '{fullDestPath}' because a file or directory with the same name already exists."); } mockFileDataAccessor.MoveDirectory(fullSourcePath, fullDestPath); }