@@ -504,6 +504,19 @@ public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories()
504504 Assert . AreEqual ( testPath , entries . First ( ) ) ;
505505 }
506506
507+ [ Test ]
508+ public void MockDirectory_GetFiles_ShouldThrowDirectoryNotFoundException_IfPathDoesNotExists ( )
509+ {
510+ // Arrange
511+ var fileSystem = new MockFileSystem ( ) ;
512+
513+ // Act
514+ TestDelegate action = ( ) => fileSystem . Directory . GetFiles ( @"c:\Foo" , "*a.txt" ) ;
515+
516+ // Assert
517+ Assert . Throws < DirectoryNotFoundException > ( action ) ;
518+ }
519+
507520 [ Test ]
508521 public void MockDirectory_GetFiles_Returns_Files ( )
509522 {
@@ -569,6 +582,42 @@ public void MockDirectory_GetDirectories_Returns_Child_Directories()
569582 Assert . IsTrue ( directories . Contains ( @"A:\folder1\folder4\" ) ) ;
570583 }
571584
585+ [ Test ]
586+ public void MockDirectory_GetDirectories_WithTopDirectories_ShouldOnlyReturnTopDirectories ( )
587+ {
588+ // Arrange
589+ var fileSystem = new MockFileSystem ( ) ;
590+ fileSystem . AddDirectory ( @"C:\Folder\.foo\" ) ;
591+ fileSystem . AddDirectory ( @"C:\Folder\foo" ) ;
592+ fileSystem . AddDirectory ( @"C:\Folder\foo.foo" ) ;
593+ fileSystem . AddDirectory ( @"C:\Folder\.foo\.foo" ) ;
594+ fileSystem . AddFile ( @"C:\Folder\.foo\bar" , new MockFileData ( string . Empty ) ) ;
595+
596+ // Act
597+ var actualResult = fileSystem . Directory . GetDirectories ( @"c:\Folder\" , "*.foo" ) ;
598+
599+ // Assert
600+ Assert . That ( actualResult , Is . EquivalentTo ( new [ ] { @"C:\Folder\.foo\" , @"C:\Folder\foo.foo\" } ) ) ;
601+ }
602+
603+ [ Test ]
604+ public void MockDirectory_GetDirectories_WithAllDirectories_ShouldReturnsAllMatchingSubFolders ( )
605+ {
606+ // Arrange
607+ var fileSystem = new MockFileSystem ( ) ;
608+ fileSystem . AddDirectory ( @"C:\Folder\.foo\" ) ;
609+ fileSystem . AddDirectory ( @"C:\Folder\foo" ) ;
610+ fileSystem . AddDirectory ( @"C:\Folder\foo.foo" ) ;
611+ fileSystem . AddDirectory ( @"C:\Folder\.foo\.foo" ) ;
612+ fileSystem . AddFile ( @"C:\Folder\.foo\bar" , new MockFileData ( string . Empty ) ) ;
613+
614+ // Act
615+ var actualResult = fileSystem . Directory . GetDirectories ( @"c:\Folder\" , "*.foo" , SearchOption . AllDirectories ) ;
616+
617+ // Assert
618+ Assert . That ( actualResult , Is . EquivalentTo ( new [ ] { @"C:\Folder\.foo\" , @"C:\Folder\foo.foo\" , @"C:\Folder\.foo\.foo\" } ) ) ;
619+ }
620+
572621 [ Test ]
573622 public void MockDirectory_GetDirectories_ShouldThrowWhenPathIsNotMocked ( )
574623 {
@@ -587,15 +636,10 @@ public void MockDirectory_GetDirectories_ShouldThrowWhenPathIsNotMocked()
587636 } ) ;
588637
589638 // Act
590- try
591- {
592- fileSystem . Directory . GetDirectories ( @"c:\d" ) ;
593- // Assert
594- Assert . Fail ( ) ;
595- }
596- catch ( DirectoryNotFoundException )
597- {
598- }
639+ TestDelegate action = ( ) => fileSystem . Directory . GetDirectories ( @"c:\d" ) ;
640+
641+ // Assert
642+ Assert . Throws < DirectoryNotFoundException > ( action ) ;
599643 }
600644
601645 [ Test ]
0 commit comments