fix: Trigger correct notifications when moving directories (#865)#869
Conversation
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Outdated
Show resolved
Hide resolved
Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs
Outdated
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
vbreuss
left a comment
There was a problem hiding this comment.
Thanks for the PR, @stogle. I really like the general approach and have some suggestions for improvement.
I also explained the change I made in #866 that you deleted that currently fail the build on the real file system.
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Outdated
Show resolved
Hide resolved
|
Thanks for the review @vbreuss. I'm not surprised that some changes are needed. I will look at it again tomorrow. I just saw the build failure, but I'm sure that all the tests passed locally before I pushed? Anyway, I'll figure it out. |
@stogle: Please note the TestSettings project: |
|
@vbreuss I've reinstated the code that I removed, refactored the logic in |
I completely understand the difficulties and I am working on finding and fixing all edge cases. |
There was a problem hiding this comment.
Pull Request Overview
Fixes FileSystemWatcherMock notifications for directory moves across the watched boundary: on Windows emit Created/Deleted when moving into/out of the watched path, and on non-Windows emit Renamed.
- Refactors watcher path matching and rename handling to correctly emit Created/Deleted on Windows for cross-boundary moves
- Adjusts event args construction to override FullPath via reflection; updates tests and adds Windows-specific cases for moves into/out of the watched path
- Minor test fix to use absolute watcher paths for reliable separator handling
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs | Adds Windows-specific tests for file and directory moves into/out of the watched path; renames methods to clarify Renamed semantics; parameterizes IncludeSubdirectories. |
| Tests/Testably.Abstractions.Testing.Tests/FileSystem/FileSystemWatcherMockTests.cs | Ensures watcher is created with an absolute path to validate FullPath/Name behavior consistently. |
| Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs | Refactors path matching (MatchesWatcherPath), adjusts rename handling to Created/Deleted on Windows, and overrides FileSystemEventArgs/RenamedEventArgs FullPath via reflection. |
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/FileSystem/FileSystemWatcherMock.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileSystemWatcher/NotifyFiltersTests.cs
Show resolved
Hide resolved
|
This is addressed in release v4.3.9. |
|
@vbreuss I have a theory about these hacks around constructing If |
@stogle: You are right 😄 : |
|
Ah, I get it now. That explains the failures I was seeing when I tried removing them myself. And your new PR not only improves performance but makes it clearer when and why the hacks are needed. |
This PR attempts to fix missing notifications from
FileSystemWatcherMockon Windows, when moving directories into or out of the watched path, as described in #865.On Windows, moving a directory from a location outside the watched path to a location inside the watched path should trigger a Created event. Similarly, moving a directory from a location inside the watched path to a location outside the watched path should trigger a Deleted event. On other platforms, these moves should trigger a Rename event instead.