Skip to content

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

@koyote

Description

@koyote

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions