diff --git a/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs
index 92e933f17..2a98a7e48 100644
--- a/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs
+++ b/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs
@@ -380,6 +380,15 @@ public override string[] GetFileSystemEntries(string path, string searchPattern)
return dirs.Union(files).ToArray();
}
+ ///
+ public override string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
+ {
+ var dirs = GetDirectories(path, searchPattern, searchOption);
+ var files = GetFiles(path, searchPattern, searchOption);
+
+ return dirs.Union(files).ToArray();
+ }
+
///
public override DateTime GetLastAccessTime(string path)
{
@@ -644,25 +653,19 @@ public override IEnumerable EnumerateFiles(string path, string searchPat
///
public override IEnumerable EnumerateFileSystemEntries(string path)
{
- var fileSystemEntries = new List(GetFiles(path));
- fileSystemEntries.AddRange(GetDirectories(path));
- return fileSystemEntries;
+ return GetFileSystemEntries(path);
}
///
public override IEnumerable EnumerateFileSystemEntries(string path, string searchPattern)
{
- var fileSystemEntries = new List(GetFiles(path, searchPattern));
- fileSystemEntries.AddRange(GetDirectories(path, searchPattern));
- return fileSystemEntries;
+ return GetFileSystemEntries(path, searchPattern);
}
///
public override IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
{
- var fileSystemEntries = new List(GetFiles(path, searchPattern, searchOption));
- fileSystemEntries.AddRange(GetDirectories(path, searchPattern, searchOption));
- return fileSystemEntries;
+ return GetFileSystemEntries(path, searchPattern, searchOption);
}
#if FEATURE_ENUMERATION_OPTIONS
diff --git a/src/System.IO.Abstractions/DirectoryBase.cs b/src/System.IO.Abstractions/DirectoryBase.cs
index 934a6f4ae..bdac3c586 100644
--- a/src/System.IO.Abstractions/DirectoryBase.cs
+++ b/src/System.IO.Abstractions/DirectoryBase.cs
@@ -95,6 +95,9 @@ internal DirectoryBase() { }
///
public abstract string[] GetFileSystemEntries(string path, string searchPattern);
+ ///
+ public abstract string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption);
+
///
public abstract DateTime GetLastAccessTime(string path);
diff --git a/src/System.IO.Abstractions/DirectoryWrapper.cs b/src/System.IO.Abstractions/DirectoryWrapper.cs
index 2830f22f2..cf60e4369 100644
--- a/src/System.IO.Abstractions/DirectoryWrapper.cs
+++ b/src/System.IO.Abstractions/DirectoryWrapper.cs
@@ -156,6 +156,12 @@ public override string[] GetFileSystemEntries(string path, string searchPattern)
return Directory.GetFileSystemEntries(path, searchPattern);
}
+ ///
+ public override string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
+ {
+ return Directory.GetFileSystemEntries(path, searchPattern, searchOption);
+ }
+
///
public override DateTime GetLastAccessTime(string path)
{
diff --git a/src/System.IO.Abstractions/IDirectory.cs b/src/System.IO.Abstractions/IDirectory.cs
index d09a9cda4..14ef6d1b3 100644
--- a/src/System.IO.Abstractions/IDirectory.cs
+++ b/src/System.IO.Abstractions/IDirectory.cs
@@ -77,6 +77,8 @@ public interface IDirectory
string[] GetFileSystemEntries(string path);
///
string[] GetFileSystemEntries(string path, string searchPattern);
+ ///
+ string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption);
///
DateTime GetLastAccessTime(string path);
///
diff --git a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
index 0ab2617e9..5b3bfdfc0 100644
--- a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
+++ b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Security.AccessControl;
@@ -956,6 +956,24 @@ public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories()
Assert.AreEqual(testPath, entries.Last());
}
+ [Test]
+ public void MockDirectory_GetFileSystemEntries_ShouldNotReturnSubDirectory_WithSearchOption()
+ {
+ string testPath = XFS.Path(@"c:\foo\bar.txt");
+ string testDir = XFS.Path(@"c:\foo\bar");
+ string testSubDir = XFS.Path(@"c:\foo\bar\baz");
+ var fileSystem = new MockFileSystem(new Dictionary
+ {
+ { testPath, new MockFileData("Demo text content") },
+ { testSubDir, new MockDirectoryData() },
+ });
+
+ var entries = fileSystem.Directory.GetFileSystemEntries(XFS.Path(@"c:\foo"), "*", SearchOption.TopDirectoryOnly).OrderBy(k => k);
+ Assert.AreEqual(2, entries.Count());
+ Assert.AreEqual(testDir, entries.First());
+ Assert.AreEqual(testPath, entries.Last());
+ }
+
[Test]
public void MockDirectory_GetFiles_ShouldThrowArgumentNullException_IfPathParamIsNull()
{
diff --git a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap
index ca0811fbe..c4f48df3c 100644
--- a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap
+++ b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 5.0.snap
@@ -6,7 +6,6 @@
"Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)"
],
"MissingMembers": [
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)",
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.SearchOption)"
+ "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)"
]
}
diff --git a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap
index 9def4d0c1..397b7ff86 100644
--- a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap
+++ b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET 6.0.snap
@@ -7,7 +7,6 @@
],
"MissingMembers": [
"System.IO.Abstractions.IFileSystemInfo ResolveLinkTarget(System.String, Boolean)",
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)",
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.SearchOption)"
+ "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)"
]
}
diff --git a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 2.1.snap b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 2.1.snap
index 45d84fc64..2accb8a3b 100644
--- a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 2.1.snap
+++ b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 2.1.snap
@@ -11,7 +11,6 @@
"System.Collections.Generic.IEnumerable`1[System.String] EnumerateFiles(System.String, System.String, System.IO.EnumerationOptions)",
"System.String[] GetDirectories(System.String, System.String, System.IO.EnumerationOptions)",
"System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)",
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.SearchOption)",
"System.String[] GetFiles(System.String, System.String, System.IO.EnumerationOptions)"
]
}
diff --git a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap
index ca0811fbe..c4f48df3c 100644
--- a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap
+++ b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Core 3.1.snap
@@ -6,7 +6,6 @@
"Void SetAccessControl(System.String, System.Security.AccessControl.DirectorySecurity)"
],
"MissingMembers": [
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)",
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.SearchOption)"
+ "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.EnumerationOptions)"
]
}
diff --git a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap
index fe8d6034a..7cb3b9523 100644
--- a/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap
+++ b/tests/System.IO.Abstractions.Tests/__snapshots__/ApiParityTests.Directory_.NET Framework 4.6.1.snap
@@ -1,6 +1,4 @@
{
"ExtraMembers": [],
- "MissingMembers": [
- "System.String[] GetFileSystemEntries(System.String, System.String, System.IO.SearchOption)"
- ]
+ "MissingMembers": []
}
diff --git a/version.json b/version.json
index 0515ee918..a3fd5217d 100644
--- a/version.json
+++ b/version.json
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "17.1",
+ "version": "17.2",
"assemblyVersion": {
"precision": "major"
},