diff --git a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs index 12d5e9be5..de4a26c04 100644 --- a/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs +++ b/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs @@ -124,7 +124,7 @@ public bool DeleteContainer(IStorageLocation location, bool recursive = false) { foreach (IStorageLocation key in children) { - DeleteContainer(key); + DeleteContainer(key, recursive); } } else if (children.Any()) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs index bd82ff1ed..5f962b9e3 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/DeleteTests.cs @@ -147,6 +147,30 @@ public void Delete_Recursive_WithSubdirectory_ShouldDeleteDirectoryWithContent( FileSystem.Should().NotHaveDirectory(subdirectoryPath); } + [SkippableTheory] + [AutoData] + public void Delete_Recursive_WithFileInSubdirectory_ShouldDeleteDirectoryWithContent( + string path, string subdirectory, string fileName, string fileContent) + { + FileSystem.Directory.CreateDirectory(path); + string filePath = FileSystem.Path.Combine(path, fileName); + FileSystem.File.WriteAllText(filePath, fileContent); + + string subdirectoryPath = FileSystem.Path.Combine(path, subdirectory); + FileSystem.Directory.CreateDirectory(subdirectoryPath); + string subdirectoryFilePath = FileSystem.Path.Combine(path, subdirectory, fileName); + FileSystem.File.WriteAllText(subdirectoryFilePath, fileContent); + + FileSystem.Should().HaveDirectory(path); + + FileSystem.Directory.Delete(path, true); + + FileSystem.Should().NotHaveDirectory(path); + FileSystem.Should().NotHaveFile(filePath); + FileSystem.Should().NotHaveDirectory(subdirectoryPath); + FileSystem.Should().NotHaveFile(subdirectoryFilePath); + } + [SkippableTheory] [AutoData] public void Delete_ShouldAdjustTimes(string path, string subdirectoryName)