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

IDirectoryInfoFactory.Wrap loses part of absolute path when used with MockFileSystem #1049

Closed
koyote opened this issue Nov 3, 2023 · 4 comments · Fixed by #1079
Closed
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on state: released Issues that are released type: bug Issues that describe misbehaving functionality

Comments

@koyote
Copy link

koyote commented Nov 3, 2023

Describe the bug
If you provide the MockFileSystem's DirectoryInfo.Wrap method with a DirectoryInfo that has an absolute path, the resulting IDirectoryInfo has the wrong file path.

To Reproduce

using Xunit;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;

[Fact]
public void Test()
{
    var fs = new MockFileSystem();
    var directoryInfo = new DirectoryInfo(@"C:\subfolder\file");
    var wrappedDirectoryInfo = fs.DirectoryInfo.Wrap(directoryInfo);

    Assert.Equal(directoryInfo.FullName, wrappedDirectoryInfo.FullName); // wrappedDirectoryInfo returns "C:\file"
}

Expected behaviour
The test above is expected to pass.

Actual behaviour

Assert.Equal() Failure
             ↓ (pos 3)
Expected: C:\subfolder\file
Actual:   C:\file
             ↑ (pos 3)

Additional context
Tested on Windows 10, .Net 7, System.IO.Abstractions version 19.2.69

@koyote koyote added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Nov 3, 2023
@fgreinacher
Copy link
Contributor

fgreinacher commented Jan 9, 2024

Thanks for reporting and sorry for the late response @koyote! Do you know if this has ever worked?

@fgreinacher fgreinacher added state: ready to pick Issues that are ready for being worked on area: testinghelpers Issues that address the testing helpers and removed state: needs discussion Issues that need further discussion labels Jan 9, 2024
@koyote
Copy link
Author

koyote commented Jan 9, 2024

Hi @fgreinacher, I do not, no.
I just recently started using this library and quickly encountered the above bug.

But just looking at the code for DirectoryInfo.Wrap:

public IDirectoryInfo Wrap(DirectoryInfo directoryInfo)
{
    if (directoryInfo == null)
    {
        return null;
    }

    return new MockDirectoryInfo(mockFileSystem, directoryInfo.Name);
}

It looks like it's sending in directoryInfo.Name, which is only the dir name, not the full path.
I'd assume changing that to directoryInfo.FullName would fix it but I don't quite have time at the moment to verify that; maybe this weekend.

@vbreuss
Copy link
Member

vbreuss commented Jan 22, 2024

Please note, that the same issue also applies when wrapping a FileInfo. I fixed both issues with #1079.

@mergify mergify bot closed this as completed in #1079 Jan 22, 2024
mergify bot pushed a commit that referenced this issue Jan 22, 2024
Use the full path when wrapping a `FileInfo` or `DirectoryInfo` to preserve the relevant information.

*Fixes #1049*
Copy link

This is addressed in release v20.0.15.

@github-actions github-actions bot added the state: released Issues that are released label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on state: released Issues that are released type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants