Skip to content

DirectoryInfo.Name returns different result for root path between mock and real file system #697

@brinkdinges

Description

@brinkdinges

Describe the bug
When you call DirectoryInfo.Name, the result is an empty string for a root path in the mocked version. The real file system returns "C:\".

To Reproduce
I'm using version 13.2.10 and the TestingHelpers project from NuGet. These unit tests succeed, which should not happen:

[Test]
public void DirectoryName_DifferentForRoot()
{
   var mock = new MockFileSystem();
   var real = new FileSystem();

   var nameInMock = mock.DirectoryInfo.FromDirectoryName("C:\\").Name;
   var nameInReal = real.DirectoryInfo.FromDirectoryName("C:\\").Name;

   Assert.AreEqual("", nameInMock);
   Assert.AreEqual("C:\\", nameInReal);
}

[Test]
public void DirectoryName_IdenticalForFile()
{
   var mock = new MockFileSystem();
   var real = new FileSystem();
   
   var nameInMock = mock.DirectoryInfo.FromDirectoryName("C:\\test.sldprt").Name;
   var nameInReal = real.DirectoryInfo.FromDirectoryName("C:\\test.sldprt").Name;

   Assert.AreEqual("test.sldprt", nameInMock);
   Assert.AreEqual("test.sldprt", nameInReal);
}

Expected behavior
I'd expect the directory name to always be the same for mocked and real file systems.

Additional context
Link to the docs: https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.name?view=net-5.0

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