Skip to content

Commit 9a99ea4

Browse files
committed
Also fix it for UNC drives
1 parent c408bc5 commit 9a99ea4

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

Source/Testably.Abstractions.Testing/MockFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public MockFileSystem WithDrive(string? drive,
223223
Action<IStorageDrive>? driveCallback = null)
224224
{
225225
IStorageDrive driveInfoMock =
226-
drive == null
226+
drive == null || string.Equals(drive, "\\", StringComparison.Ordinal)
227227
? Storage.MainDrive
228228
: Storage.GetOrAddDrive(drive);
229229
driveCallback?.Invoke(driveInfoMock);

Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ public IEnumerable<IStorageDrive> GetDrives()
367367
DriveInfoMock drive = DriveInfoMock.New(driveName, _fileSystem);
368368
return _drives.GetOrAdd(drive.GetName(), _ =>
369369
{
370-
GetOrCreateContainer(GetLocation(drive.GetName()), InMemoryContainer.NewDirectory);
370+
IStorageLocation rootLocation =
371+
InMemoryLocation.New(_fileSystem, drive, drive.GetName());
372+
GetOrCreateContainer(rootLocation, InMemoryContainer.NewDirectory);
371373
return drive;
372374
});
373375
}

Tests/Testably.Abstractions.Testing.Tests/MockFileSystemTests.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public async Task ToString_ShouldContainStorageInformation()
116116

117117
string result = sut.ToString();
118118

119-
await That(result).Contains("directories: 0, files: 1");
119+
await That(result).Contains("directories: 1, files: 1");
120120
}
121121

122122
[Theory]
@@ -246,13 +246,13 @@ await That(drives).HasSingle().Matching(d
246246
[Fact]
247247
public async Task WithDrive_ShouldInitializeDrivesWithRootDirectory()
248248
{
249-
MockFileSystem sut = new MockFileSystem().WithDrive("d");
250-
List<IFileInfo> files = sut.DriveInfo.GetDrives()
249+
MockFileSystem sut = new MockFileSystem().WithDrive("V");
250+
List<IFileSystemInfo> fileSystemInfos = sut.DriveInfo.GetDrives()
251251
.SelectMany(drive => drive.RootDirectory
252-
.EnumerateFiles("*", SearchOption.AllDirectories))
252+
.EnumerateFileSystemInfos("*", SearchOption.AllDirectories))
253253
.ToList();
254254

255-
await That(files.Count).IsEqualTo(0);
255+
await That(fileSystemInfos).HasCount(0);
256256
}
257257

258258
[Theory]
@@ -319,6 +319,24 @@ public async Task WithUncDrive_ShouldCreateUncDrive(
319319
await That(result).IsEqualTo(contents);
320320
}
321321

322+
[Theory]
323+
[AutoData]
324+
public async Task WithUncDrive_ShouldInitializeDrivesWithRootDirectory(
325+
string server)
326+
{
327+
MockFileSystem sut = new();
328+
string uncPrefix = new(sut.Path.DirectorySeparatorChar, 2);
329+
string uncDrive = $"{uncPrefix}{server}";
330+
sut.WithUncDrive(uncDrive);
331+
IDriveInfo drive = sut.DriveInfo.New(uncDrive);
332+
333+
List<IFileSystemInfo> fileSystemInfos = drive.RootDirectory
334+
.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)
335+
.ToList();
336+
337+
await That(fileSystemInfos).HasCount(0);
338+
}
339+
322340
[Theory]
323341
[AutoData]
324342
public async Task WithUncDrive_ShouldNotBeIncludedInGetDrives(

Tests/Testably.Abstractions.Testing.Tests/Storage/InMemoryContainerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ public async Task ToString_File_ShouldIncludePathAndFileSize(byte[] bytes)
303303
MockFileSystem fileSystem = new();
304304
string expectedPath = fileSystem.Path.GetFullPath("foo.txt");
305305
fileSystem.File.WriteAllBytes(expectedPath, bytes);
306-
IStorageContainer sut = fileSystem.StorageContainers.Single();
306+
IStorageContainer sut = fileSystem.StorageContainers
307+
.Single(x => x.Type == FileSystemTypes.File);
307308

308309
string? result = sut.ToString();
309310

0 commit comments

Comments
 (0)