diff --git a/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 39eb41947..bc845c1e1 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, "*", enumerationOptions.RecurseSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); + return GetDirectories(path, "*", EnumerationOptionsToSearchOption(enumerationOptions)); } #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, "*", enumerationOptions.RecurseSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); + return GetFiles(path, "*", EnumerationOptionsToSearchOption(enumerationOptions)); } #endif @@ -638,5 +638,42 @@ private string ReplaceLastOccurrence(string source, string find, string replace) var result = source.Remove(place, find.Length).Insert(place, replace); return result; } + +#if FEATURE_ENUMERATION_OPTIONS + private SearchOption EnumerationOptionsToSearchOption(EnumerationOptions enumerationOptions) + { + static Exception CreateExceptionForUnsupportedProperty(string propertyName) + { + return new NotSupportedException( + $"Changing EnumerationOptions.{propertyName} is not yet implemented for the mock file system." + ); + } + + if (enumerationOptions.AttributesToSkip != (FileAttributes.System | FileAttributes.Hidden)) + { + throw CreateExceptionForUnsupportedProperty("AttributesToSkip"); + } + if (!enumerationOptions.IgnoreInaccessible) + { + throw CreateExceptionForUnsupportedProperty("IgnoreInaccessible"); + } + if (enumerationOptions.MatchCasing != MatchCasing.PlatformDefault) + { + throw CreateExceptionForUnsupportedProperty("MatchCasing"); + } + if (enumerationOptions.MatchType != MatchType.Simple) + { + throw CreateExceptionForUnsupportedProperty("MatchType"); + } + if (enumerationOptions.ReturnSpecialDirectories) + { + throw CreateExceptionForUnsupportedProperty("ReturnSpecialDirectories"); + } + + return enumerationOptions.RecurseSubdirectories + ? SearchOption.AllDirectories + : SearchOption.TopDirectoryOnly; + } +#endif } } diff --git a/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj b/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj index 819264659..ce27c683d 100644 --- a/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj +++ b/src/System.IO.Abstractions.TestingHelpers/System.IO.Abstractions.TestingHelpers.csproj @@ -3,7 +3,7 @@ System.IO.Abstractions.TestingHelpers System.IO.Abstractions.TestingHelpers A set of pre-built mocks to help when testing file system interactions. - netstandard2.0;netstandard2.1;net461 + netstandard2.1;netstandard2.0;net461 https://github.com/System-IO-Abstractions/System.IO.Abstractions MIT testing diff --git a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs index 18fb1bf05..93185a1e8 100644 --- a/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs +++ b/tests/System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryInfoTests.cs @@ -188,12 +188,7 @@ public void MockDirectoryInfo_EnumerateFileSystemInfos_ShouldReturnDirectoriesAn 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(); diff --git a/tests/System.IO.Abstractions.TestingHelpers.Tests/System.IO.Abstractions.TestingHelpers.Tests.csproj b/tests/System.IO.Abstractions.TestingHelpers.Tests/System.IO.Abstractions.TestingHelpers.Tests.csproj index 2f195e99f..d00e39f75 100644 --- a/tests/System.IO.Abstractions.TestingHelpers.Tests/System.IO.Abstractions.TestingHelpers.Tests.csproj +++ b/tests/System.IO.Abstractions.TestingHelpers.Tests/System.IO.Abstractions.TestingHelpers.Tests.csproj @@ -1,6 +1,6 @@  - netcoreapp2.1;netcoreapp3.0 + netcoreapp3.1;netcoreapp2.1 $(TargetFrameworks);net461 The unit tests for our pre-built mocks System.IO.Abstractions.TestingHelpers.Tests diff --git a/tests/System.IO.Abstractions.Tests/System.IO.Abstractions.Tests.csproj b/tests/System.IO.Abstractions.Tests/System.IO.Abstractions.Tests.csproj index 485063e6e..66459ff3f 100644 --- a/tests/System.IO.Abstractions.Tests/System.IO.Abstractions.Tests.csproj +++ b/tests/System.IO.Abstractions.Tests/System.IO.Abstractions.Tests.csproj @@ -1,6 +1,6 @@  - netcoreapp3.0;netcoreapp2.1 + netcoreapp3.1;netcoreapp2.1 $(TargetFrameworks);net461 The unit tests for our the core abstractions System.IO.Abstractions.Tests