Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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 @@ -16,7 +16,7 @@ public class MockDirectory : DirectoryBase
{
private readonly IMockFileDataAccessor mockFileDataAccessor;
private string currentDirectory;
Comment thread
fgreinacher marked this conversation as resolved.

Comment thread
fgreinacher marked this conversation as resolved.
Outdated
/// <inheritdoc />
public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, FileBase fileBase, string currentDirectory) :
this(mockFileDataAccessor, currentDirectory)
Expand All @@ -32,7 +32,6 @@ public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, string currentD
mockFileDataAccessor ?? throw new ArgumentNullException(nameof(mockFileDataAccessor));
}


/// <inheritdoc />
Comment thread
fgreinacher marked this conversation as resolved.
public override IDirectoryInfo CreateDirectory(string path)
{
Expand Down Expand Up @@ -110,7 +109,17 @@ public override IFileSystemInfo CreateSymbolicLink(string path, string pathToTar
/// <inheritdoc />
public override IDirectoryInfo CreateTempSubdirectory(string prefix = null)
{
throw CommonExceptions.NotImplemented();
prefix ??= "";
string potentialTempDirectory;

// Perform directory name generation in a loop, just in case the randomly generated name already exists.
do
{
var randomDir = $"{prefix}{Path.GetRandomFileName()}";
potentialTempDirectory = Path.Combine(Path.GetTempPath(), randomDir);
} while (Exists(potentialTempDirectory));

return CreateDirectoryInternal(potentialTempDirectory);
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,37 @@ public void MockDirectory_CreateDirectory_ShouldSucceedIfTryingToCreateUNCPathSh
Assert.IsTrue(fileSystem.Directory.Exists(@"\\server\share\"));
}

#if FEATURE_CREATE_TEMP_SUBDIRECTORY
[Test]
public void MockDirectory_CreateTempSubdirectory_ShouldCreateSubdirectoryInTempDirectory()
{
// Arrange
var fileSystem = new MockFileSystem();

// Act
var result = fileSystem.Directory.CreateTempSubdirectory();

// Assert
Assert.IsTrue(fileSystem.Directory.Exists(result.FullName));
Assert.IsTrue(result.FullName.Contains(Path.GetTempPath()));
}

[Test]
public void MockDirectory_CreateTempSubdirectoryWithPrefix_ShouldCreateDirectoryWithGivenPrefixInTempDirectory()
{
// Arrange
var fileSystem = new MockFileSystem();

// Act
var result = fileSystem.Directory.CreateTempSubdirectory("foo-");

// Assert
Assert.IsTrue(fileSystem.Directory.Exists(result.FullName));
Assert.IsTrue(Path.GetFileName(result.FullName).StartsWith("foo-"));
Assert.IsTrue(result.FullName.Contains(Path.GetTempPath()));
}
#endif

[Test]
public void MockDirectory_Delete_ShouldDeleteDirectory()
{
Expand Down