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.File.Move on Windows and .Net 8 doesn't rename a file name's case #1140

Open
El-Gor-do opened this issue Aug 9, 2024 · 6 comments
Assignees
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
Possibly related to #1138
On Windows and .Net 8, FileSystem.File.Move successfully renames a file if the destination has a different case than source whereas MockFileSystem.File.Move doesn't rename the file.

To Reproduce
Steps to reproduce the behavior:
Using System.IO.Abstractions.TestingHelpers 21.0.29

static void Main(string[] args)
{
    FileSystem fs = new FileSystem();
    MockFileSystem mockFs = new MockFileSystem();

    Console.WriteLine("Real file system");
    MoveFile(fs);

    Console.WriteLine("Mock file system");
    MoveFile(mockFs);
}

static void MoveFile(IFileSystem fileSystem)
{
    string tempDir = fileSystem.Path.GetTempPath();
    string src = fileSystem.Path.Combine(tempDir, "src.txt");
    string dest = fileSystem.Path.Combine(tempDir, "SRC.TXT");  // different case

    // create source file
    using (_ = fileSystem.File.Create(src))
    {
    }

    // move file
    fileSystem.File.Move(src, dest);

    // check the moved file's name exact case
    string movedFile = fileSystem.Directory.GetFiles(tempDir, "src.txt").First();
    Console.WriteLine($"Successfully moved \"{src}\" to \"{movedFile}\"");

    if (fileSystem.File.Exists(src))
        fileSystem.File.Delete(src);

    if (fileSystem.File.Exists(dest))
        fileSystem.File.Delete(dest);
}

Actual output

Real file system
Successfully moved "C:\Users\El-Gor-do\AppData\Local\Temp\src.txt" to "C:\Users\El-Gor-do\AppData\Local\Temp\SRC.TXT"
Mock file system
Successfully moved "C:\temp\src.txt" to "C:\temp\src.txt"

Expected behavior
MockFileSystem.File.Move should successfully rename the file to SRC.TXT

Real file system
Successfully moved "C:\Users\El-Gor-do\AppData\Local\Temp\src.txt" to "C:\Users\El-Gor-do\AppData\Local\Temp\SRC.TXT"
Mock file system
Successfully moved "C:\temp\src.txt" to "C:\temp\SRC.TXT"
@El-Gor-do El-Gor-do added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Aug 9, 2024
@vbreuss
Copy link
Member

vbreuss commented Aug 11, 2024

When fixing this, it would probably be easy to also have an eye out for the correct behaviour in File.Copy and File.Replace when source and destination differ only in casing...

@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 11, 2024
@RobinDoesUnity
Copy link

Hi @vbreuss, @El-Gor-do,
first time contributor here. I would like to look into fixing this.

@vbreuss
Copy link
Member

vbreuss commented Sep 21, 2024

Hi @vbreuss, @El-Gor-do,
first time contributor here. I would like to look into fixing this.

Please feel welcome to create a pull request.

@KasinathCR
Copy link

@vbreuss - I'll look into this, Bro. Please assign it to me👍

@vbreuss
Copy link
Member

vbreuss commented Oct 17, 2024

@RobinDoesUnity :
Are you still working on this issue?

@RobinDoesUnity
Copy link

Hi @vbreuss, you can assign it to someone else. Sorry, I was busy these days.

@vbreuss vbreuss assigned KasinathCR and unassigned RobinDoesUnity Oct 17, 2024
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

4 participants