Skip to content

Commit

Permalink
EnumerationOptions With recursion (#652)
Browse files Browse the repository at this point in the history
Co-authored-by: p-storm <[email protected]>
  • Loading branch information
P-Storm and p-storm authored Oct 12, 2020
1 parent cf626f8 commit c0cd28d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public override string[] GetDirectories(string path, string searchPattern, Searc
#if FEATURE_ENUMERATION_OPTIONS
public override string[] GetDirectories(string path, string searchPattern, EnumerationOptions enumerationOptions)
{
return GetDirectories(path, "*");
return GetDirectories(path, "*", enumerationOptions.RecurseSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
}
#endif

Expand Down Expand Up @@ -206,7 +206,7 @@ public override string[] GetFiles(string path, string searchPattern, SearchOptio
#if FEATURE_ENUMERATION_OPTIONS
public override string[] GetFiles(string path, string searchPattern, EnumerationOptions enumerationOptions)
{
return GetFiles(path, "*");
return GetFiles(path, "*", enumerationOptions.RecurseSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,51 @@ public void MockDirectoryInfo_EnumerateFileSystemInfos_ShouldReturnDirectoriesAn
Assert.That(result.Length, Is.EqualTo(2));
}

[Test]
public void MockDirectoryInfo_EnumerateFileSystemInfos_ShouldReturnDirectoriesAndNamesWithSearchPatternRecursive()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("") },
{ XFS.Path(@"c:\temp\folder\folder"), new MockDirectoryData() },
{ XFS.Path(@"c:\temp\folder\older"), new MockDirectoryData() }
});

var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\"));
var result = directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).ToArray();

Assert.That(result.Length, Is.EqualTo(5));
}

#if FEATURE_ENUMERATION_OPTIONS
[Test]
public void MockDirectoryInfo_EnumerateFileSystemInfos_ShouldReturnDirectoriesAndNamesWithSearchPatternRecursiveEnumerateOptions()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ XFS.Path(@"c:\temp\folder\file.txt"), new MockFileData("") },
{ XFS.Path(@"c:\temp\folder\folder"), new MockDirectoryData() },
{ XFS.Path(@"c:\temp\folder\older"), new MockDirectoryData() }
});

var directoryInfo = new MockDirectoryInfo(fileSystem, XFS.Path(@"c:\"));

var enumerationOptions = new EnumerationOptions()
{
MatchType = MatchType.Win32,
RecurseSubdirectories = true,
IgnoreInaccessible = true,
ReturnSpecialDirectories = false,
AttributesToSkip = FileAttributes.Hidden,
MatchCasing = MatchCasing.PlatformDefault,
};

var result = directoryInfo.EnumerateFileSystemInfos("*", enumerationOptions).ToArray();

Assert.That(result.Length, Is.EqualTo(5));
}
#endif

[Test]
public void MockDirectoryInfo_GetParent_ShouldReturnDirectoriesAndNamesWithSearchPattern()
{
Expand Down

0 comments on commit c0cd28d

Please sign in to comment.