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,8 +243,11 @@ public void AddFile(string path, MockFileData mockFile)
}

var directoryPath = Path.GetDirectoryName(fixedPath);

if (!DirectoryExistsWithoutFixingPath(directoryPath))
if (directoryPath == null)
vbreuss marked this conversation as resolved.
Show resolved Hide resolved
{
AddDrive(fixedPath, new MockDriveData());
}
else if (!DirectoryExistsWithoutFixingPath(directoryPath))
{
AddDirectory(directoryPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,57 @@
);
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_Constructor_ShouldAddDifferentDrivesIfNotExist()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
[@"d:\foo\bar\"] = new MockDirectoryData(),
});

var drivesInfo = fileSystem.DriveInfo.GetDrives();
var fooExists = fileSystem.Directory.Exists(@"d:\foo\");
var barExists = fileSystem.Directory.Exists(@"d:\foo\bar\");

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True);

Check failure on line 471 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True) Expected: True But was: False

Check failure on line 471 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True) Expected: True But was: False

Check failure on line 471 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True) Expected: True But was: False

Check failure on line 471 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True) Expected: True But was: False

Check failure on line 471 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True) Expected: True But was: False

Check failure on line 471 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

MockFileSystem_Constructor_ShouldAddDifferentDrivesIfNotExist

Assert.That(drivesInfo.Any(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Is.True) Expected: True But was: False
Assert.That(fooExists, Is.True);
Assert.That(barExists, Is.True);
}

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

var drivesInfo = fileSystem.DriveInfo.GetDrives();

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items);

Check failure on line 487 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

MockFileSystem_Constructor_ShouldNotDuplicateDrives

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items) Expected: exactly one item But was: no items

Check failure on line 487 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

MockFileSystem_Constructor_ShouldNotDuplicateDrives

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items) Expected: exactly one item But was: no items

Check failure on line 487 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

MockFileSystem_Constructor_ShouldNotDuplicateDrives

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items) Expected: exactly one item But was: no items

Check failure on line 487 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

MockFileSystem_Constructor_ShouldNotDuplicateDrives

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items) Expected: exactly one item But was: no items

Check failure on line 487 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

MockFileSystem_Constructor_ShouldNotDuplicateDrives

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items) Expected: exactly one item But was: no items

Check failure on line 487 in tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileSystemTests.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

MockFileSystem_Constructor_ShouldNotDuplicateDrives

Assert.That(drivesInfo.Where(d => string.Equals(d.Name, @"D:\", StringComparison.InvariantCultureIgnoreCase)), Has.Exactly(1).Items) Expected: exactly one item But was: no items
}

[Test]
public void MockFileSystem_DefaultState_DefaultTempDirectoryExists()
Expand Down
Loading