diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 5b9e7968b..242bb0d5e 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -503,7 +503,7 @@ 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 (string.Equals(fullSourcePath, fullDestPath, StringComparison.Ordinal)) { throw new IOException("Source and destination path must be different."); } @@ -537,9 +537,13 @@ public override void Move(string sourceDirName, string destDirName) if (mockFileDataAccessor.Directory.Exists(fullDestPath) || mockFileDataAccessor.File.Exists(fullDestPath)) { - throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath); + // In Windows, file/dir names are case sensetive, C:\\temp\\src and C:\\temp\\SRC and treated different + if (XFS.IsUnixPlatform() || + !string.Equals(fullSourcePath, fullDestPath, StringComparison.OrdinalIgnoreCase)) + { + throw CommonExceptions.CannotCreateBecauseSameNameAlreadyExists(fullDestPath); + } } - mockFileDataAccessor.MoveDirectory(fullSourcePath, fullDestPath); } @@ -653,7 +657,7 @@ public override IEnumerable 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); @@ -661,7 +665,7 @@ private string FixPrefix(string path, string originalPath) .TrimStart(mockFileDataAccessor.Path.DirectorySeparatorChar); return mockFileDataAccessor.Path.Combine(originalPath, pathWithoutOriginalPath); } - + #if FEATURE_ENUMERATION_OPTIONS /// public override IEnumerable EnumerateDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions) diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 3a0711ff3..fae8b65a3 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -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)); + } } \ No newline at end of file