Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
throw ExceptionFactory.DirectoryNotFound(location.FullPath);
}

return EnumerateLocationsImpl(location, type, requestParentAccess, searchPattern,
enumerationOptions, parentContainer);
}

/// <summary>
/// Internal implementation of location enumeration that uses yield return.
/// This method contains the actual enumeration logic and is only called after validation passes.
/// </summary>
private IEnumerable<IStorageLocation> EnumerateLocationsImpl(
IStorageLocation location,
FileSystemTypes type,
bool requestParentAccess,
string searchPattern,
EnumerationOptions? enumerationOptions,
IStorageContainer parentContainer)
{
IDisposable parentAccess = new NoOpDisposable();
if (requestParentAccess)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateDirectories_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");

sut.DirectoryInfo.New("foo").EnumerateDirectories();

Expand All @@ -93,6 +94,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateDirectories_String_EnumerationOptions_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";
EnumerationOptions enumerationOptions = new();

Expand All @@ -109,6 +111,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateDirectories_String_SearchOption_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";
SearchOption searchOption = SearchOption.AllDirectories;

Expand All @@ -124,6 +127,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateDirectories_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";

sut.DirectoryInfo.New("foo").EnumerateDirectories(searchPattern);
Expand All @@ -138,6 +142,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFiles_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");

sut.DirectoryInfo.New("foo").EnumerateFiles();

Expand All @@ -151,6 +156,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFiles_String_EnumerationOptions_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";
EnumerationOptions enumerationOptions = new();

Expand All @@ -167,6 +173,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFiles_String_SearchOption_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";
SearchOption searchOption = SearchOption.AllDirectories;

Expand All @@ -182,6 +189,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFiles_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";

sut.DirectoryInfo.New("foo").EnumerateFiles(searchPattern);
Expand All @@ -196,6 +204,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFileSystemInfos_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");

sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos();

Expand All @@ -209,6 +218,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFileSystemInfos_String_EnumerationOptions_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";
EnumerationOptions enumerationOptions = new();

Expand All @@ -225,6 +235,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFileSystemInfos_String_SearchOption_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";
SearchOption searchOption = SearchOption.AllDirectories;

Expand All @@ -240,6 +251,7 @@ await That(sut.Statistics.DirectoryInfo["foo"])
public async Task Method_EnumerateFileSystemInfos_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string searchPattern = "foo";

sut.DirectoryInfo.New("foo").EnumerateFileSystemInfos(searchPattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(nameof(IDirectory.De
public async Task Method_EnumerateDirectories_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";

sut.Directory.EnumerateDirectories(path);
Expand All @@ -118,6 +119,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateDirectories_String_String_EnumerationOptions_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";
EnumerationOptions enumerationOptions = new();
Expand All @@ -135,6 +137,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateDirectories_String_String_SearchOption_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";
SearchOption searchOption = SearchOption.AllDirectories;
Expand All @@ -151,6 +154,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateDirectories_String_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";

Expand All @@ -166,6 +170,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateFiles_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";

sut.Directory.EnumerateFiles(path);
Expand All @@ -181,6 +186,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateFiles_String_String_EnumerationOptions_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";
EnumerationOptions enumerationOptions = new();
Expand All @@ -197,6 +203,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(nameof(IDirectory.En
public async Task Method_EnumerateFiles_String_String_SearchOption_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";
SearchOption searchOption = SearchOption.AllDirectories;
Expand All @@ -213,6 +220,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateFiles_String_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";

Expand All @@ -228,6 +236,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateFileSystemEntries_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";

sut.Directory.EnumerateFileSystemEntries(path);
Expand All @@ -243,6 +252,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateFileSystemEntries_String_String_EnumerationOptions_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";
EnumerationOptions enumerationOptions = new();
Expand All @@ -261,6 +271,7 @@ public async Task
Method_EnumerateFileSystemEntries_String_String_SearchOption_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";
SearchOption searchOption = SearchOption.AllDirectories;
Expand All @@ -277,6 +288,7 @@ await That(sut.Statistics.Directory).OnlyContainsMethodCall(
public async Task Method_EnumerateFileSystemEntries_String_String_ShouldRegisterCall()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
string path = "foo";
string searchPattern = "foo";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ await That(Act).Throws<DirectoryNotFoundException>()
await That(FileSystem.Directory.Exists(path)).IsFalse();
}

[Theory]
[AutoData]
public async Task
EnumerateDirectories_MissingDirectory_ShouldThrowDirectoryNotFoundExceptionImmediately(
string path)
{
string expectedPath = FileSystem.Path.Combine(BasePath, path);

void Act() =>
_ = FileSystem.Directory.EnumerateDirectories(path);

await That(Act).Throws<DirectoryNotFoundException>()
.WithMessageContaining($"'{expectedPath}'").And
.WithHResult(-2147024893);
await That(FileSystem.Directory.Exists(path)).IsFalse();
}

[Fact]
public async Task EnumerateDirectories_RelativePath_ShouldNotIncludeTrailingSlash()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ await That(Act).Throws<DirectoryNotFoundException>()
await That(FileSystem.Directory.Exists(path)).IsFalse();
}

[Theory]
[AutoData]
public async Task
EnumerateFileSystemEntries_MissingDirectory_ShouldThrowDirectoryNotFoundExceptionImmediately(
string path)
{
string expectedPath = FileSystem.Path.Combine(BasePath, path);

void Act() =>
_ = FileSystem.Directory.EnumerateFileSystemEntries(path);

await That(Act).Throws<DirectoryNotFoundException>()
.WithMessageContaining($"'{expectedPath}'").And
.WithHResult(-2147024893);
await That(FileSystem.Directory.Exists(path)).IsFalse();
}

[Theory]
[AutoData]
public async Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ await That(Act).Throws<DirectoryNotFoundException>()
await That(FileSystem.Directory.Exists(path)).IsFalse();
}

[Theory]
[AutoData]
public async Task
EnumerateFiles_MissingDirectory_ShouldThrowDirectoryNotFoundExceptionImmediately(
string path)
{
string expectedPath = FileSystem.Path.Combine(BasePath, path);

void Act() =>
_ = FileSystem.Directory.EnumerateFiles(path);

await That(Act).Throws<DirectoryNotFoundException>()
.WithMessageContaining($"'{expectedPath}'").And
.WithHResult(-2147024893);
await That(FileSystem.Directory.Exists(path)).IsFalse();
}

[Theory]
[AutoData]
public async Task
Expand Down
Loading