@@ -182,7 +182,7 @@ public void MockDirectory_GetFiles_ShouldFilterByExtensionBasedSearchPatternWith
182182 var result = fileSystem . Directory . GetFiles ( XFS . Path ( @"c:\" ) , "*.gif" , SearchOption . AllDirectories ) ;
183183
184184 // Assert
185- Assert . That ( result , Is . EquivalentTo ( expected ) ) ;
185+ Assert . That ( result , Is . EquivalentTo ( expected ) ) ;
186186 }
187187
188188 [ Test ]
@@ -598,6 +598,29 @@ public void MockDirectory_Delete_ShouldDeleteDirectory()
598598 Assert . IsFalse ( fileSystem . Directory . Exists ( XFS . Path ( @"c:\bar" ) ) ) ;
599599 }
600600
601+ [ Test ]
602+ public void MockDirectory_Delete_ShouldNotDeleteAllDirectories ( )
603+ {
604+ // Arrange
605+ var folder1Path = XFS . Path ( @"D:\Test\Program" ) ;
606+ var folder1SubFolderPath = XFS . Path ( @"D:\Test\Program\Subfolder" ) ;
607+ var folder2Path = XFS . Path ( @"D:\Test\Program_bak" ) ;
608+
609+ var fileSystem = new MockFileSystem ( ) ;
610+
611+ fileSystem . AddDirectory ( folder1Path ) ;
612+ fileSystem . AddDirectory ( folder2Path ) ;
613+ fileSystem . AddDirectory ( folder1SubFolderPath ) ;
614+
615+ // Act
616+ fileSystem . Directory . Delete ( folder1Path , recursive : true ) ;
617+
618+ // Assert
619+ Assert . IsFalse ( fileSystem . Directory . Exists ( folder1Path ) ) ;
620+ Assert . IsFalse ( fileSystem . Directory . Exists ( folder1SubFolderPath ) ) ;
621+ Assert . IsTrue ( fileSystem . Directory . Exists ( folder2Path ) ) ;
622+ }
623+
601624 [ Test ]
602625 [ WindowsOnly ( WindowsSpecifics . CaseInsensitivity ) ]
603626 public void MockDirectory_Delete_ShouldDeleteDirectoryCaseInsensitively ( )
@@ -700,7 +723,7 @@ public void MockDirectory_Delete_ShouldDeleteDirectoryRecursively()
700723 public void MockDirectory_GetFileSystemEntries_Returns_Files_And_Directories ( )
701724 {
702725 string testPath = XFS . Path ( @"c:\foo\bar.txt" ) ;
703- string testDir = XFS . Path ( @"c:\foo\bar" ) ;
726+ string testDir = XFS . Path ( @"c:\foo\bar" ) ;
704727 var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData >
705728 {
706729 { testPath , new MockFileData ( "Demo text content" ) } ,
@@ -829,7 +852,7 @@ public void MockDirectory_GetFiles_ShouldFindFilesContainingTwoOrMoreDots()
829852 var actualResult = fileSystem . Directory . GetFiles ( XFS . Path ( @"c:\" ) , XFS . Path ( @"foo..r\*" ) ) ;
830853
831854 // Assert
832- Assert . That ( actualResult , Is . EquivalentTo ( new [ ] { testPath } ) ) ;
855+ Assert . That ( actualResult , Is . EquivalentTo ( new [ ] { testPath } ) ) ;
833856 }
834857
835858#if NET40
@@ -925,7 +948,7 @@ public void MockDirectory_GetDirectories_WithTopDirectories_ShouldOnlyReturnTopD
925948 var actualResult = fileSystem . Directory . GetDirectories ( XFS . Path ( @"c:\Folder\" ) , "*.foo" ) ;
926949
927950 // Assert
928- Assert . That ( actualResult , Is . EquivalentTo ( new [ ] { XFS . Path ( @"C:\Folder\.foo" ) , XFS . Path ( @"C:\Folder\foo.foo" ) } ) ) ;
951+ Assert . That ( actualResult , Is . EquivalentTo ( new [ ] { XFS . Path ( @"C:\Folder\.foo" ) , XFS . Path ( @"C:\Folder\foo.foo" ) } ) ) ;
929952 }
930953
931954 [ Test ]
@@ -1141,7 +1164,7 @@ public void Move_DirectoryExistsWithDifferentCase_DirectorySuccessfullyMoved()
11411164 }
11421165
11431166 [ TestCaseSource ( "GetPathsForMoving" ) ]
1144- public void MockDirectory_Move_ShouldMove ( string sourceDirName , string destDirName , string filePathOne , string filePathTwo )
1167+ public void MockDirectory_Move_ShouldMoveDirectories ( string sourceDirName , string destDirName , string filePathOne , string filePathTwo )
11451168 {
11461169 // Arrange
11471170 var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData >
@@ -1159,6 +1182,26 @@ public void MockDirectory_Move_ShouldMove(string sourceDirName, string destDirNa
11591182 Assert . IsTrue ( fileSystem . File . Exists ( XFS . Path ( destDirName + filePathTwo ) ) ) ;
11601183 }
11611184
1185+ [ Test ]
1186+ public void MockDirectory_Move_ShouldMoveFiles ( )
1187+ {
1188+ string sourceFilePath = XFS . Path ( @"c:\demo.txt" ) ;
1189+ string sourceFileContent = "this is some content" ;
1190+
1191+ var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData >
1192+ {
1193+ { sourceFilePath , new MockFileData ( sourceFileContent ) }
1194+ } ) ;
1195+
1196+ string destFilePath = XFS . Path ( @"c:\demo1.txt" ) ;
1197+
1198+ fileSystem . Directory . Move ( sourceFilePath , destFilePath ) ;
1199+
1200+ Assert . That ( fileSystem . FileExists ( destFilePath ) , Is . True ) ;
1201+ Assert . That ( fileSystem . FileExists ( sourceFilePath ) , Is . False ) ;
1202+ Assert . That ( fileSystem . GetFile ( destFilePath ) . TextContents , Is . EqualTo ( sourceFileContent ) ) ;
1203+ }
1204+
11621205 [ Test ]
11631206 public void MockDirectory_Move_ShouldMoveDirectoryAtrributes ( )
11641207 {
@@ -1211,17 +1254,18 @@ public void MockDirectory_Move_ShouldMoveDirectoryWithReadOnlySubDirectory()
12111254 }
12121255
12131256 [ Test ]
1214- public void MockDirectory_GetCurrentDirectory_ShouldReturnValueFromFileSystemConstructor ( ) {
1257+ public void MockDirectory_GetCurrentDirectory_ShouldReturnValueFromFileSystemConstructor ( )
1258+ {
12151259 string directory = XFS . Path ( @"D:\folder1\folder2" ) ;
12161260 var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) , directory ) ;
12171261
12181262 var actual = fileSystem . Directory . GetCurrentDirectory ( ) ;
12191263
12201264 Assert . AreEqual ( directory , actual ) ;
12211265 }
1222-
1266+
12231267 [ Test ]
1224- public void MockDirectory_GetCurrentDirectory_ShouldReturnDefaultPathWhenNotSet ( )
1268+ public void MockDirectory_GetCurrentDirectory_ShouldReturnDefaultPathWhenNotSet ( )
12251269 {
12261270 string directory = XFS . Path ( @"C:\" ) ;
12271271
@@ -1233,7 +1277,8 @@ public void MockDirectory_GetCurrentDirectory_ShouldReturnDefaultPathWhenNotSet(
12331277 }
12341278
12351279 [ Test ]
1236- public void MockDirectory_SetCurrentDirectory_ShouldChangeCurrentDirectory ( ) {
1280+ public void MockDirectory_SetCurrentDirectory_ShouldChangeCurrentDirectory ( )
1281+ {
12371282 string directory = XFS . Path ( @"D:\folder1\folder2" ) ;
12381283 var fileSystem = new MockFileSystem ( ) ;
12391284
@@ -1278,7 +1323,7 @@ public void MockDirectory_GetParent_ShouldReturnADirectoryInfoIfPathDoesNotExist
12781323 var fileSystem = new MockFileSystem ( ) ;
12791324
12801325 // Act
1281- var actualResult = fileSystem . Directory . GetParent ( XFS . Path ( @"c:\directory\does\not\exist" ) ) ;
1326+ var actualResult = fileSystem . Directory . GetParent ( XFS . Path ( @"c:\directory\does\not\exist" ) ) ;
12821327
12831328 // Assert
12841329 Assert . IsNotNull ( actualResult ) ;
@@ -1331,9 +1376,9 @@ public static IEnumerable<string[]> MockDirectory_GetParent_Cases
13311376 {
13321377 get
13331378 {
1334- yield return new [ ] { XFS . Path ( @"c:\a" ) , XFS . Path ( @"c:\" ) } ;
1335- yield return new [ ] { XFS . Path ( @"c:\a\b\c\d" ) , XFS . Path ( @"c:\a\b\c" ) } ;
1336- yield return new [ ] { XFS . Path ( @"c:\a\b\c\d\" ) , XFS . Path ( @"c:\a\b\c" ) } ;
1379+ yield return new [ ] { XFS . Path ( @"c:\a" ) , XFS . Path ( @"c:\" ) } ;
1380+ yield return new [ ] { XFS . Path ( @"c:\a\b\c\d" ) , XFS . Path ( @"c:\a\b\c" ) } ;
1381+ yield return new [ ] { XFS . Path ( @"c:\a\b\c\d\" ) , XFS . Path ( @"c:\a\b\c" ) } ;
13371382 }
13381383 }
13391384
0 commit comments