System.IO.Abstractions
System.IO.Abstractions copied to clipboard
MockFileSystem does not support Root directories
Describe the bug Including a Root drive/directory in a MockFileSystem causes ArgumentNullException at line 82 of MockFileSystem.cs
To Reproduce To recreate, execute the following line of code:
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\demo", new MockDirectoryData() },
{ @"z:\", new MockDirectoryData() },
{ @"Z:\foo", new MockDirectoryData() }
});
Expected behavior
"Z:" should be a valid directory.
Additional context
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\demo", new MockDirectoryData() },
//{ @"z:\", new MockDirectoryData() },
{ @"Z:\foo", new MockDirectoryData() }
}); //This produces no exception
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ @"c:\demo", new MockDirectoryData() },
//{ @"z:\", new MockDirectoryData() },
{ @"Z:\foo", new MockDirectoryData() }
}); //This produces an exception.
Thanks for reporting!
Hi, in the Additional context section, the 2 examples are the same even though the comments say the 1st one does not throw an exception whereas the 2nd does.
I think in the 2nd example, the 2nd directory mock should not be commented, just like in the To reproduce section
For reference, the exception thrown is
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
And here's the stack trace:
Dictionary`2.FindValue(TKey key)
Dictionary`2.TryGetValue(TKey key, TValue& value)
MockFileSystem.DirectoryExistsWithoutFixingPath(String path)
MockFileSystem.AddFile(String path, MockFileData mockFile)
MockFileSystem.ctor(IDictionary`2 files, String currentDirectory)