diff --git a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs index f85f45beb..12d5e9be5 100644 --- a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs +++ b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs @@ -173,6 +173,7 @@ public IEnumerable<IStorageLocation> EnumerateLocations( enumerationOptions ??= EnumerationOptionsHelper.Compatible; string fullPath = location.FullPath; + string fullPathWithoutTrailingSlash = fullPath; #if NETSTANDARD2_0 if (!fullPath.EndsWith($"{_fileSystem.Path.DirectorySeparatorChar}")) #else @@ -181,6 +182,10 @@ public IEnumerable<IStorageLocation> EnumerateLocations( { fullPath += _fileSystem.Path.DirectorySeparatorChar; } + else if (_fileSystem.Path.GetPathRoot(fullPath) != fullPath) + { + fullPathWithoutTrailingSlash = fullPathWithoutTrailingSlash.TrimEnd(_fileSystem.Path.DirectorySeparatorChar); + } foreach (KeyValuePair<IStorageLocation, IStorageContainer> item in _containers .Where(x => x.Key.FullPath.StartsWith(fullPath, @@ -192,7 +197,7 @@ public IEnumerable<IStorageLocation> EnumerateLocations( item.Key.FullPath.TrimEnd(_fileSystem.Path .DirectorySeparatorChar)); if (!enumerationOptions.RecurseSubdirectories && - parentPath?.Equals(location.FullPath, + parentPath?.Equals(fullPathWithoutTrailingSlash, InMemoryLocation.StringComparisonMode) != true) { continue; diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs index 2f9a22d4a..2352ba67e 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs @@ -9,21 +9,6 @@ public abstract partial class EnumerateDirectoriesTests<TFileSystem> : FileSystemTestBase<TFileSystem> where TFileSystem : IFileSystem { - [SkippableTheory] - [InlineData("Folder", @"Folder\SubFolder")] - [InlineData(@"Folder\", @"Folder\SubFolder")] - [InlineData(@"Folder\..\.\Folder", @"Folder\..\.\Folder\SubFolder")] - public void MockDirectory_EnumerateDirectories_ShouldReturnPathsPrefixedWithQueryPath( - string queryPath, string expectedPath) - { - var fileSystem = new MockFileSystem(); - fileSystem.Directory.CreateDirectory("Folder/SubFolder"); - - var actualResult = fileSystem.Directory.EnumerateDirectories(queryPath); - - actualResult.Should().BeEquivalentTo(new[] { expectedPath }); - } - [SkippableFact] public void EnumerateDirectories_AbsolutePath_ShouldNotIncludeTrailingSlash() { @@ -261,4 +246,16 @@ public void result.Count().Should().Be(2); } + + [SkippableFact] + public void EnumerateDirectories_WithTrailingSlash_ShouldEnumerateSubdirectories() + { + string queryPath = @"Folder\"; + string expectedPath = @"Folder\SubFolder"; + FileSystem.Directory.CreateDirectory("Folder/SubFolder"); + + IEnumerable<string> actualResult = FileSystem.Directory.EnumerateDirectories(queryPath); + + actualResult.Should().BeEquivalentTo(expectedPath); + } }