Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockFileSystem does not support Root directories #702

Open
derecskey opened this issue Feb 17, 2021 · 2 comments
Open

MockFileSystem does not support Root directories #702

derecskey opened this issue Feb 17, 2021 · 2 comments
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality

Comments

@derecskey
Copy link

derecskey commented Feb 17, 2021

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.
@derecskey derecskey added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Feb 17, 2021
@fgreinacher
Copy link
Contributor

fgreinacher commented Feb 18, 2021

Thanks for reporting!

@fgreinacher fgreinacher added area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on and removed state: needs discussion Issues that need further discussion labels Feb 18, 2021
@tuan-tu-tran
Copy link
Collaborator

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: ready to pick Issues that are ready for being worked on type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

3 participants