diff --git a/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs index f7533a43f..39eb41947 100644 --- a/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -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 @@ -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 diff --git a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index 330c8f40b..18fb1bf05 100644 --- a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -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 + { + { 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 + { + { 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() {