Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockFileSystem.Directory.Move fails on Windows if destination has different case from source #1138

Open
El-Gor-do opened this issue Aug 7, 2024 · 2 comments
Labels
flag: good-first-issue Issues that are good for first time contributors state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality

Comments

@El-Gor-do
Copy link

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"
@El-Gor-do El-Gor-do added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Aug 7, 2024
@vbreuss
Copy link
Member

vbreuss commented Aug 8, 2024

Thanks for reporting. This behaviour is probably due to a different behaviour on Linux between .NET Framework and .NET Core. On .NET Framework also the real file system throws an IOException (see here).

@vbreuss vbreuss added state: ready to pick Issues that are ready for being worked on flag: good-first-issue Issues that are good for first time contributors and removed state: needs discussion Issues that need further discussion labels Aug 8, 2024
@El-Gor-do
Copy link
Author

I forgot to mention that I am running on .Net 8 only, not .Net Framework. My applications work fine because I use FileSystem as my IFileSystem implementation, it's only my tests that fail because I replace FileSystem with MockFileSystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: good-first-issue Issues that are good for first time contributors state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

2 participants