-
-
Notifications
You must be signed in to change notification settings - Fork 9
fix: DirectoryMock.EnumerateDirectories does not throw exceptions until enumerated #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Split InMemoryStorage.EnumerateLocations into validation and implementation methods. Validation and exceptions now occur immediately when method is called, while enumeration logic happens during iteration as expected. Co-authored-by: vbreuss <[email protected]>
Updated EnumerateDirectories statistics tests to create directories first, ensuring they test successful method calls rather than exception paths. The fix maintains proper statistics tracking while enabling immediate exception throwing for missing directories. Co-authored-by: vbreuss <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where DirectoryMock.EnumerateDirectories (and related enumeration methods) did not match the behavior of the real Directory.EnumerateDirectories implementation. The real file system throws IO exceptions immediately when the enumeration method is called on a non-existent directory, but the mock implementation only threw exceptions during iteration.
- Split
InMemoryStorage.EnumerateLocationsinto validation and implementation phases to throw exceptions immediately - Added new test cases to verify immediate exception throwing behavior for all enumeration methods
- Updated statistics tests to create directories before enumeration to avoid exception scenarios
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs | Refactored EnumerateLocations to separate immediate validation from lazy enumeration implementation |
| Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateDirectoriesTests.cs | Added test verifying immediate exception throwing on missing directory |
| Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFilesTests.cs | Added test verifying immediate exception throwing on missing directory |
| Tests/Testably.Abstractions.Tests/FileSystem/Directory/EnumerateFileSystemInfosTests.cs | Added test verifying immediate exception throwing on missing directory |
| Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryStatisticsTests.cs | Updated enumeration statistics tests to create directories first |
| Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/DirectoryInfoStatisticsTests.cs | Updated enumeration statistics tests to create directories first |
Test Results 37 files ± 0 37 suites ±0 21m 32s ⏱️ +17s For more details on these failures, see this check. Results for commit eb0bb1a. ± Comparison against base commit 46eb8ff. This pull request removes 36227 and adds 36327 tests. Note that renamed tests count towards both.This pull request removes 1784 skipped tests and adds 1784 skipped tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
|
|
This is addressed in release v4.3.6. |

The
DirectoryMock.EnumerateDirectoriesmethod was not matching the behavior of the realDirectory.EnumerateDirectoriesimplementation. The real implementation throws IO exceptions (likeDirectoryNotFoundException) immediately when the method is called, but the mock implementation only threw these exceptions when the returnedIEnumerablewas actually enumerated.Problem
This discrepancy could cause tests to pass when they should fail, or miss edge cases in exception handling logic.
Solution
Split
InMemoryStorage.EnumerateLocationsinto two methods:EnumerateLocations()- Performs immediate validation (directory exists, valid search pattern) and throws exceptions synchronouslyEnumerateLocationsImpl()- Contains the actual yield-based enumeration logic that executes during iterationThis ensures validation and exception throwing happens at method call time, while preserving the lazy enumeration behavior for the actual iteration over results.
Changes
The fix applies to all enumeration methods:
EnumerateDirectories()EnumerateFiles()EnumerateFileSystemEntries()