Skip to content

MockFileSystem.Directory.GetDirectories returns absolute paths instead of relative paths #815

Description

@tuan-tu-tran

Describe the bug
Calling MockFileSystem.Directory.GetDirectories(@"some\path") returns absolute paths instead of relative paths

To Reproduce
In this code

varmockFs=newMockFileSystem();mockFs.Directory.CreateDirectory(@"foo\bar");varoutput=mockFs.Directory.GetDirectories("foo");

output is an array with a single string: C:\foo\bar, which is incorrect.

Expected behavior
In the same example, output should be an array with a single string foo\bar

Additional context
Here's a more comprehensive code snippet that shows:

  • how the System.IO.Directory class behaves
  • that FileSystem.Directory behaves correctly
  • that MockFileSystem.Directory behaves incorrectly
[TestMethod]publicvoidDirectory_GetDirectories_Should_Return_Relative_Paths(){//This shows how the system classes behave : it returns one relative directoryDirectory.CreateDirectory(@"foo\bar");vardirs1=Directory.GetDirectories("foo");CollectionAssert.AreEqual(new[]{@"foo\bar"},dirs1);//passes//This shows that the real FileSystem behaves correctly, same as system classesvarfs=newFileSystem();vardirs2=fs.Directory.GetDirectories("foo");CollectionAssert.AreEqual(dirs1,dirs2);//passes//This shows that the MockFileSystem behaves incorrectly : it returns one absolute directory pathvarmockFs=newMockFileSystem();mockFs.Directory.CreateDirectory(@"foo\bar");vardirs3=mockFs.Directory.GetDirectories("foo");Console.WriteLine(dirs3[0]);// C:\foo\barCollectionAssert.AreEqual(dirs1,dirs3,"dirs3 should equal dirs1");//fails}

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: good-first-issueIssues that are good for first time contributorsstate: in workIssues that are currently worked ontype: 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