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

fix: fixed mock file system exception when using root path as a parameter #1132

Merged
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)
vbreuss marked this conversation as resolved.
Show resolved Hide resolved
{
AddDrive(fixedPath, new MockDriveData());
SetEntry(fixedPath, mockFile);
vbreuss marked this conversation as resolved.
Show resolved Hide resolved
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(),
vbreuss marked this conversation as resolved.
Show resolved Hide resolved
[@"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
Loading