Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ 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))
if (XFS.IsUnixPlatform() ? mockFileDataAccessor.StringOperations.Equals(fullSourcePath, fullDestPath)
: string.Equals(fullSourcePath, fullDestPath, StringComparison.Ordinal))
{
throw new IOException("Source and destination path must be different.");
}
Expand Down Expand Up @@ -534,12 +535,21 @@ public override void Move(string sourceDirName, string destDirName)
{
throw CommonExceptions.CouldNotFindPartOfPath(destDirName);
}

if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath))
if (XFS.IsUnixPlatform())
{
throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath);
if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath))
{
throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath);
}
}
else if (!string.Equals(fullSourcePath, fullDestPath, StringComparison.OrdinalIgnoreCase))
{
// In Windows, file/dir names are case sensetive, C:\\temp\\src and C:\\temp\\SRC and treated different
if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath))
{
throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath);
}
}

mockFileDataAccessor.MoveDirectory(fullSourcePath, fullDestPath);
}

Expand Down Expand Up @@ -653,15 +663,15 @@ public override IEnumerable<string> EnumerateDirectories(string path, string sea
.Where(p => !mockFileDataAccessor.StringOperations.Equals(p, path))
.Select(p => FixPrefix(p, originalPath));
}

private string FixPrefix(string path, string originalPath)
{
var normalizedOriginalPath = mockFileDataAccessor.Path.GetFullPath(originalPath);
var pathWithoutOriginalPath = path.Substring(normalizedOriginalPath.Length)
.TrimStart(mockFileDataAccessor.Path.DirectorySeparatorChar);
return mockFileDataAccessor.Path.Combine(originalPath, pathWithoutOriginalPath);
}

#if FEATURE_ENUMERATION_OPTIONS
/// <inheritdoc />
public override IEnumerable<string> EnumerateDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2204,4 +2204,19 @@ public async Task MockDirectory_Exists_ShouldReturnTrue_IfArgIsFrontSlashAndRoot

await That(fileSystem.Directory.Exists("/")).IsEqualTo(true);
}

[Test]
public static void MockDirectory_Move_ShouldNotThrowException_InWindows_When_SourceAndDestinationDifferOnlyInCasing()
{
// Arrange
MockFileSystem mockFs = new MockFileSystem();
string tempDir = mockFs.Path.GetTempPath();
string src = mockFs.Path.Combine(tempDir, "src");
string dest = mockFs.Path.Combine(tempDir, "SRC");
IDirectoryInfo srcDir = mockFs.DirectoryInfo.New(src);
srcDir.Create();

// Act & Assert
Assert.DoesNotThrow(() => mockFs.Directory.Move(src, dest));
}
}