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 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 EnumerateLocations( { fullPath += _fileSystem.Path.DirectorySeparatorChar; } + else if (_fileSystem.Path.GetPathRoot(fullPath) != fullPath) + { + fullPathWithoutTrailingSlash = fullPathWithoutTrailingSlash.TrimEnd(_fileSystem.Path.DirectorySeparatorChar); + } foreach (KeyValuePair item in _containers .Where(x => x.Key.FullPath.StartsWith(fullPath, @@ -192,7 +197,7 @@ public IEnumerable 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 179f5b011..cd1593bcf 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs @@ -246,4 +246,16 @@ public void result.Count().Should().Be(2); } + + [SkippableFact] + public void EnumerateDirectories_WithTrailingSlash_ShouldEnumerateSubdirectories() + { + string queryPath = @"foo" + FileSystem.Path.DirectorySeparatorChar; + string expectedPath = FileSystem.Path.Combine("foo", "bar"); + FileSystem.Directory.CreateDirectory(expectedPath); + + IEnumerable actualResult = FileSystem.Directory.EnumerateDirectories(queryPath); + + actualResult.Should().BeEquivalentTo(expectedPath); + } }