Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ internal FileSystemInitializer(FileSystemInitializer<TFileSystem> parent,
_basePath = FileSystem.Path.Combine(parent._basePath, subdirectory.Name);
}

internal FileSystemInitializer(FileSystemInitializer<TFileSystem> parent,
string subdirectory)
Comment thread
vbreuss marked this conversation as resolved.
Outdated
{
FileSystem = parent.FileSystem;
using IDisposable release = FileSystem.IgnoreStatistics();
_initializedFileSystemInfos = parent._initializedFileSystemInfos;
_basePath = FileSystem.Path.Combine(parent._basePath, subdirectory);
}

#region IFileSystemInitializer<TFileSystem> Members

/// <inheritdoc cref="IFileSystemInitializer{TFileSystem}.BaseDirectory" />
Expand Down Expand Up @@ -146,7 +155,7 @@ private IDirectoryInfo WithDirectory(DirectoryDescription directory)

FileSystem.Directory.CreateDirectory(directoryInfo.FullName);

FileSystemInitializer<TFileSystem> subdirectoryInitializer = new(this, directoryInfo);
FileSystemInitializer<TFileSystem> subdirectoryInitializer = new(this, directory.Name);
foreach (FileSystemInfoDescription children in directory.Children)
{
subdirectoryInitializer.WithFileOrDirectory(children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ public async Task With_FilesAndDirectories_ShouldBothBeCreated(string fileName,
await That(fileSystem.File.Exists(fileName)).IsTrue();
await That(fileSystem.Directory.Exists(directoryName)).IsTrue();
}

[Theory]
[AutoData]
public async Task With_FilesAndDirectoriesWithMultiplePathComponents_ShouldBeCreatedAtTheCorrectPath(
string level1, string level2, string fileName)
{
string directoryPath = Path.Combine(level1, level2);
Comment thread
vbreuss marked this conversation as resolved.
string filePath = Path.Combine(directoryPath, fileName);
FileDescription fileDescription = new(fileName);
DirectoryDescription directoryDescription = new(directoryPath, fileDescription);
MockFileSystem fileSystem = new();
IFileSystemInitializer<MockFileSystem> sut = fileSystem.Initialize();

sut.With(directoryDescription);

await That(fileSystem.Statistics.TotalCount).IsEqualTo(0);
await That(fileSystem.Directory.Exists(directoryPath)).IsTrue();
await That(fileSystem.File.Exists(filePath)).IsTrue();
}

[Theory]
[AutoData]
Expand Down Expand Up @@ -186,6 +205,24 @@ public async Task WithFile_MissingDirectory_ShouldCreateDirectory(string directo
await That(fileSystem.Directory.Exists(directoryPath)).IsTrue();
}

[Theory]
[AutoData]
public async Task WithFile_MultiplePathComponents_ShouldCreateDirectories(string level1,
string level2, string level3, string fileName)
{
string path = Path.Combine(level1, level2, level3, fileName);
MockFileSystem fileSystem = new();
IFileSystemInitializer<MockFileSystem> sut = fileSystem.Initialize();

sut.WithFile(path);

await That(fileSystem.Statistics.TotalCount).IsEqualTo(0);
await That(fileSystem.File.Exists(path)).IsTrue();
await That(fileSystem.Directory.Exists(level1)).IsTrue();
await That(fileSystem.Directory.Exists(Path.Combine(level1, level2))).IsTrue();
await That(fileSystem.Directory.Exists(Path.Combine(level1, level2, level3))).IsTrue();
}

[Theory]
[AutoData]
public async Task WithSubdirectories_ShouldCreateAllDirectories(string[] paths)
Expand Down
Loading