@@ -119,14 +119,13 @@ public void IncludeSubdirectories_DowngradedWhenSubdirectoryPatternRemoved()
119119 using var fileSystemWatcher = new MockFileSystemWatcher ( root . Path ) ;
120120 using var physicalFilesWatcher = new PhysicalFilesWatcher ( root . Path , fileSystemWatcher , pollForChanges : false ) ;
121121
122+ physicalFilesWatcher . CreateFileChangeToken ( "appsettings.json" ) ;
122123 physicalFilesWatcher . CreateFileChangeToken ( "sub/file.json" ) ;
123124 Assert . True ( fileSystemWatcher . IncludeSubdirectories ) ;
124125
125126 // Fire an event matching the subdirectory token to remove it from the lookup.
127+ // The remaining root-only token does not require subdirectory watching, IncludeSubdirectories should be downgraded.
126128 fileSystemWatcher . CallOnChanged ( new FileSystemEventArgs ( WatcherChangeTypes . Changed , root . Path , "sub/file.json" ) ) ;
127-
128- // Adding a new root-only token re-evaluates IncludeSubdirectories.
129- physicalFilesWatcher . CreateFileChangeToken ( "appsettings.json" ) ;
130129 Assert . False ( fileSystemWatcher . IncludeSubdirectories ) ;
131130 }
132131
@@ -145,10 +144,6 @@ public void IncludeSubdirectories_NotDowngradedWhileSubdirectoryPatternRemains()
145144 // Remove only the root-level token; the subdirectory token must keep subdirectories enabled.
146145 fileSystemWatcher . CallOnChanged ( new FileSystemEventArgs ( WatcherChangeTypes . Changed , root . Path , "appsettings.json" ) ) ;
147146 Assert . True ( fileSystemWatcher . IncludeSubdirectories ) ;
148-
149- // Trigger re-evaluation by adding another root-only token.
150- physicalFilesWatcher . CreateFileChangeToken ( "other.json" ) ;
151- Assert . True ( fileSystemWatcher . IncludeSubdirectories ) ;
152147 }
153148
154149 [ Fact ]
@@ -166,9 +161,6 @@ public void IncludeSubdirectories_NotDowngradedWhenWildcardSubdirectoryPatternRe
166161 // Remove the root-level token; the recursive wildcard token must keep subdirectories enabled.
167162 fileSystemWatcher . CallOnChanged ( new FileSystemEventArgs ( WatcherChangeTypes . Changed , root . Path , "appsettings.json" ) ) ;
168163 Assert . True ( fileSystemWatcher . IncludeSubdirectories ) ;
169-
170- physicalFilesWatcher . CreateFileChangeToken ( "other.json" ) ;
171- Assert . True ( fileSystemWatcher . IncludeSubdirectories ) ;
172164 }
173165
174166 [ Fact ]
@@ -188,6 +180,29 @@ public void IncludeSubdirectories_AlwaysTrueWhenWatcherIsAboveRoot()
188180 Assert . True ( fsw . IncludeSubdirectories ) ;
189181 }
190182
183+ [ Fact ]
184+ [ SkipOnPlatform ( TestPlatforms . Browser | TestPlatforms . iOS | TestPlatforms . tvOS , "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS" ) ]
185+ public async Task IncludeSubdirectories_StarPatternIsNotRecursive_DoesNotMatchSubdirectoryFile ( )
186+ {
187+ using var root = new TempDirectory ( GetTestFilePath ( ) ) ;
188+ using var fileSystemWatcher = new MockFileSystemWatcher ( root . Path ) ;
189+ using var physicalFilesWatcher = new PhysicalFilesWatcher ( root . Path , fileSystemWatcher , pollForChanges : false ) ;
190+
191+ IChangeToken token = physicalFilesWatcher . CreateFileChangeToken ( "*.json" ) ;
192+ Assert . False ( fileSystemWatcher . IncludeSubdirectories ) ;
193+
194+ Task changed = WhenChanged ( token ) ;
195+
196+ // A '*' pattern should not match files in subdirectories.
197+ fileSystemWatcher . CallOnChanged ( new FileSystemEventArgs ( WatcherChangeTypes . Changed , root . Path , "sub/foo.json" ) ) ;
198+ await Task . Delay ( WaitTimeForTokenToFire ) ;
199+ Assert . False ( changed . IsCompleted , "Token must not fire for an event in a subdirectory." ) ;
200+
201+ // Sanity check: a root-level event does fire the token.
202+ fileSystemWatcher . CallOnChanged ( new FileSystemEventArgs ( WatcherChangeTypes . Changed , root . Path , "foo.json" ) ) ;
203+ await changed ;
204+ }
205+
191206 [ Fact ]
192207 [ SkipOnPlatform ( TestPlatforms . Browser | TestPlatforms . iOS | TestPlatforms . tvOS , "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS" ) ]
193208 public void CreateFileChangeToken_DoesNotAllowPathsAboveRoot ( )
0 commit comments