Skip to content

Commit

Permalink
fixed mock file system exception when using root path as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jul 12, 2024
1 parent c708b42 commit 377be90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ public void AddFile(string path, MockFileData mockFile)
}

var directoryPath = Path.GetDirectoryName(fixedPath);
if (directoryPath == null)
{
AddDrive(fixedPath, new MockDriveData());
SetEntry(fixedPath, mockFile);
return;
}

if (!DirectoryExistsWithoutFixingPath(directoryPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,26 @@ public void MockFileSystem_Constructor_ThrowsForNonRootedCurrentDirectory()
);
Assert.That(ae.ParamName, Is.EqualTo("currentDirectory"));
}

[Test]
public void MockFileSystem_Constructor_ShouldSupportDifferentRootDrives()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
[@"c:\"] = new MockDirectoryData(),
[@"z:\"] = new MockDirectoryData(),
[@"d:\"] = new MockDirectoryData(),
});

var cExists = fileSystem.Directory.Exists(@"c:\");
var zExists = fileSystem.Directory.Exists(@"z:\");
var dExists = fileSystem.Directory.Exists(@"d:\");

Assert.That(fileSystem, Is.Not.Null);
Assert.That(cExists, Is.True);
Assert.That(zExists, Is.True);
Assert.That(dExists, Is.True);
}

[Test]
public void MockFileSystem_DefaultState_DefaultTempDirectoryExists()
Expand Down

0 comments on commit 377be90

Please sign in to comment.