System.IO.Abstractions
System.IO.Abstractions copied to clipboard
MockFileSystem.Directory.Move fails on Windows if destination has different case from source
Describe the bug
On Windows, FileSystem.Directory.Move is successful when the destination has a different case than source but MockFileSystem.Directory.Move throws System.IO.IOException: Source and destination path must be different.
To Reproduce
Steps to reproduce the behavior:
Using System.IO.Abstractions.TestingHelpers 21.0.29
static void Test()
{
FileSystem fs = new FileSystem();
MockFileSystem mockFs = new MockFileSystem();
Console.WriteLine("Real file system");
MoveDir(fs);
Console.WriteLine("Mock file system");
MoveDir(mockFs);
}
static void MoveDir(IFileSystem fileSystem)
{
string tempDir = fileSystem.Path.GetTempPath();
string src = fileSystem.Path.Combine(tempDir, "src");
string dest = fileSystem.Path.Combine(tempDir, "SRC"); // different case
try
{
// create source directory
IDirectoryInfo srcDir = fileSystem.DirectoryInfo.New(src);
srcDir.Create();
// move directory
fileSystem.Directory.Move(src, dest);
Console.WriteLine($"Successfully moved \"{src}\" to \"{dest}\"");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
if (fileSystem.Directory.Exists(src))
fileSystem.Directory.Delete(src);
if (fileSystem.Directory.Exists(dest))
fileSystem.Directory.Delete(dest);
}
}
Actual output
Real file system
Successfully moved "C:\Users\El-Gor-do\AppData\Local\Temp\src" to "C:\Users\El-Gor-do\AppData\Local\Temp\SRC"
Mock file system
System.IO.IOException: Source and destination path must be different.
at System.IO.Abstractions.TestingHelpers.MockDirectory.Move(String sourceDirName, String destDirName)
at IDirectoryInfoMove.Program.MoveDir(IFileSystem fileSystem) in D:\dev\bugs\IDirectoryInfoMove\IDirectoryInfoMove\Program.cs:line 33
Expected behavior MockFileSystem.Directory.Move should successfully move the directory.
Real file system
Successfully moved "C:\Users\El-Gor-do\AppData\Local\Temp\src" to "C:\Users\El-Gor-do\AppData\Local\Temp\SRC"
Mock file system
Successfully moved "C:\Users\El-Gor-do\AppData\Local\Temp\src" to "C:\Users\El-Gor-do\AppData\Local\Temp\SRC"