@@ -265,6 +265,10 @@ public void FileDialog_MixedMode_SkipsUnreadableEntry_AndKeepsReadableEntries ()
265265 . Setup ( d => d . GetFileSystemInfos ( ) )
266266 . Returns ( [ goodFile , badFile , goodDirectory ] ) ;
267267
268+ Mock . Get ( directory )
269+ . Setup ( d => d . EnumerateFileSystemInfos ( "*" , It . IsAny < EnumerationOptions > ( ) ) )
270+ . Returns ( [ goodFile , badFile , goodDirectory ] ) ;
271+
268272 using FileDialog fd = new TestableFileDialog ( fileSystem ) ;
269273 fd . OpenMode = OpenMode . Mixed ;
270274
@@ -288,6 +292,10 @@ public void FileDialog_DirectoryMode_SkipsUnreadableDirectory_AndKeepsParentNavi
288292 . Setup ( d => d . GetDirectories ( ) )
289293 . Returns ( [ goodDirectory , badDirectory ] ) ;
290294
295+ Mock . Get ( directory )
296+ . Setup ( d => d . EnumerateDirectories ( "*" , It . IsAny < EnumerationOptions > ( ) ) )
297+ . Returns ( [ goodDirectory , badDirectory ] ) ;
298+
291299 using FileDialog fd = new TestableFileDialog ( fileSystem ) ;
292300 fd . OpenMode = OpenMode . Directory ;
293301
@@ -299,6 +307,64 @@ public void FileDialog_DirectoryMode_SkipsUnreadableDirectory_AndKeepsParentNavi
299307 Assert . DoesNotContain ( fd . State . Children , c => c . Name == "bad-dir" ) ;
300308 }
301309
310+ [ Fact ]
311+ public void FileDialog_MixedMode_WhenEagerListingThrows_StillKeepsReadableEntries ( )
312+ {
313+ IFileSystem fileSystem = CreateFileSystemWithDirectory ( out IDirectoryInfo directory ) ;
314+ IFileInfo goodFile = CreateFile ( "/testdir/good.txt" , "good.txt" ) ;
315+ IDirectoryInfo goodDirectory = CreateDirectory ( "/testdir/good-dir" , "good-dir" , directory ) ;
316+
317+ Mock . Get ( directory )
318+ . Setup ( d => d . GetFileSystemInfos ( ) )
319+ . Throws ( new UnauthorizedAccessException ( ) ) ;
320+
321+ Mock . Get ( directory )
322+ . Setup ( d => d . EnumerateFileSystemInfos ( ) )
323+ . Returns ( [ goodFile , goodDirectory ] ) ;
324+
325+ Mock . Get ( directory )
326+ . Setup ( d => d . EnumerateFileSystemInfos ( "*" , It . IsAny < EnumerationOptions > ( ) ) )
327+ . Returns ( [ goodFile , goodDirectory ] ) ;
328+
329+ using FileDialog fd = new TestableFileDialog ( fileSystem ) ;
330+ fd . OpenMode = OpenMode . Mixed ;
331+
332+ fd . Path = "/testdir" ;
333+
334+ Assert . NotNull ( fd . State ) ;
335+ Assert . Contains ( fd . State ! . Children , c => c . Name == "good.txt" ) ;
336+ Assert . Contains ( fd . State . Children , c => c . Name == "good-dir" ) ;
337+ Assert . Contains ( fd . State . Children , c => c . IsParent && c . Name == ".." ) ;
338+ }
339+
340+ [ Fact ]
341+ public void FileDialog_DirectoryMode_WhenEagerListingThrows_StillKeepsReadableDirectories ( )
342+ {
343+ IFileSystem fileSystem = CreateFileSystemWithDirectory ( out IDirectoryInfo directory ) ;
344+ IDirectoryInfo goodDirectory = CreateDirectory ( "/testdir/good-dir" , "good-dir" , directory ) ;
345+
346+ Mock . Get ( directory )
347+ . Setup ( d => d . GetDirectories ( ) )
348+ . Throws ( new UnauthorizedAccessException ( ) ) ;
349+
350+ Mock . Get ( directory )
351+ . Setup ( d => d . EnumerateDirectories ( ) )
352+ . Returns ( [ goodDirectory ] ) ;
353+
354+ Mock . Get ( directory )
355+ . Setup ( d => d . EnumerateDirectories ( "*" , It . IsAny < EnumerationOptions > ( ) ) )
356+ . Returns ( [ goodDirectory ] ) ;
357+
358+ using FileDialog fd = new TestableFileDialog ( fileSystem ) ;
359+ fd . OpenMode = OpenMode . Directory ;
360+
361+ fd . Path = "/testdir" ;
362+
363+ Assert . NotNull ( fd . State ) ;
364+ Assert . Contains ( fd . State ! . Children , c => c . Name == "good-dir" ) ;
365+ Assert . Contains ( fd . State . Children , c => c . IsParent && c . Name == ".." ) ;
366+ }
367+
302368 [ Fact ]
303369 public void FileDialog_Accepting_Directory_From_Table_Keeps_Path_On_Opened_Directory ( )
304370 {
@@ -418,6 +484,10 @@ private static Mock<IDirectoryInfo> CreateDirectoryMock (string fullName, string
418484 directory . SetupGet ( d => d . LastWriteTime ) . Returns ( new DateTime ( 2026 , 1 , 1 ) ) ;
419485 directory . Setup ( d => d . GetFileSystemInfos ( ) ) . Returns ( [ ] ) ;
420486 directory . Setup ( d => d . GetDirectories ( ) ) . Returns ( [ ] ) ;
487+ directory . Setup ( d => d . EnumerateFileSystemInfos ( ) ) . Returns ( [ ] ) ;
488+ directory . Setup ( d => d . EnumerateDirectories ( ) ) . Returns ( [ ] ) ;
489+ directory . Setup ( d => d . EnumerateFileSystemInfos ( "*" , It . IsAny < EnumerationOptions > ( ) ) ) . Returns ( [ ] ) ;
490+ directory . Setup ( d => d . EnumerateDirectories ( "*" , It . IsAny < EnumerationOptions > ( ) ) ) . Returns ( [ ] ) ;
421491
422492 return directory ;
423493 }
0 commit comments