System.IO.Abstractions icon indicating copy to clipboard operation
System.IO.Abstractions copied to clipboard

MockFileSystem with currentDirectory should return only one currentDirectory

Open LosManos opened this issue 6 years ago • 2 comments

var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
    { @"myfile.txt", new MockFileData("A") },
}, @"current");

makes fileSystem.AllFiles.Single() return "current\current\current\myfile.txt" which is two too many.
I also believe there should be a prepending \.


A remedy is to prepend "current" with a slash like so"

var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
    { @"myfile.txt", new MockFileData("A") },
}, @"\current");

to give the result "\current\myfile.txt"


Although I present a work around it might be considered a but as it is imho an unexpected behaviour.

LosManos avatar May 08 '20 15:05 LosManos

Thanks for reporting! I’m wondering whether we should force currentDirectory to be an absolute path.

fgreinacher avatar May 13 '20 22:05 fgreinacher

Forcing currentDirectory to be rooted sounds ok to me.

FWIW: Retrieving Environment.CurrentDirectory alway returns a rooted path. (with drive letter in Windows and /mnt in WSL. (I have not tried WSL2)) Setting it does not have to be rooted but can be relative to current directory.

LosManos avatar May 17 '20 17:05 LosManos