@@ -1903,5 +1903,82 @@ public void MockDirectory_SetCreationTime_ShouldNotThrowWithoutTrailingBackslash
19031903 fs . Directory . SetCreationTime ( path , DateTime . Now ) ;
19041904 fs . Directory . Delete ( path ) ;
19051905 }
1906+
1907+ private static IEnumerable < TestCaseData > Failing_DirectoryMoveFromToPaths
1908+ {
1909+ get
1910+ {
1911+ var testTargetDirs = new [ ]
1912+ {
1913+ @"c:\temp2\fd\df" , @"c:\temp2\fd\" , @"c:\temp2\fd\..\fd" , @"c:\temp2\fd" , @".\..\temp2\fd\df" ,
1914+ @".\..\temp2\fd\df\.." , @".\..\temp2\fd\df\..\" , @"..\temp2\fd\" , @".\temp2\fd" , @"temp2\fd" ,
1915+ @"c:\temp3\exists2\d3" , @"c:\temp4\exists"
1916+ } ;
1917+
1918+ var testSourceDirs = new [ ] { @"c:\temp\exists\foldertomove" , @"c:\temp3\exists" , @"c:\temp3" } ;
1919+
1920+ return
1921+ from s in testSourceDirs
1922+ from t in testTargetDirs
1923+ select new TestCaseData ( XFS . Path ( s ) , XFS . Path ( t ) ) ;
1924+ }
1925+ }
1926+
1927+ [ Test ]
1928+ [ TestCaseSource ( nameof ( Failing_DirectoryMoveFromToPaths ) ) ]
1929+ public void Move_Directory_Throws_When_Target_Directory_Parent_Does_Not_Exist (
1930+ string sourceDirName ,
1931+ string targetDirName )
1932+ {
1933+ // Arange
1934+ var fileSystem = new MockFileSystem ( ) ;
1935+ fileSystem . Directory . CreateDirectory ( sourceDirName ) ;
1936+
1937+ // Act
1938+ Assert . Throws < DirectoryNotFoundException > ( ( ) =>
1939+ fileSystem . Directory . Move ( sourceDirName , targetDirName ) ) ;
1940+
1941+ // Assert
1942+ Assert . IsFalse ( fileSystem . Directory . Exists ( targetDirName ) ) ;
1943+ Assert . IsTrue ( fileSystem . Directory . Exists ( sourceDirName ) ) ;
1944+ }
1945+
1946+ private static IEnumerable < TestCaseData > Success_DirectoryMoveFromToPaths
1947+ {
1948+ get
1949+ {
1950+ var testTargetDirs = new [ ]
1951+ {
1952+ @"c:\temp2\" , @"c:\temp2" , @"c:\temp2\..\temp2" , @".\..\temp2" , @".\..\temp2\..\temp2" ,
1953+ @".\..\temp2\fd\df\..\.." , @".\..\temp2\fd\df\..\..\" , @"..\temp2" , @".\temp2" , @"\temp2" , @"temp2" ,
1954+ } ;
1955+
1956+ var testSourceDirs = new [ ] { @"c:\temp3\exists\foldertomove" , @"c:\temp3\exists" , @"c:\temp4" } ;
1957+
1958+ return
1959+ from s in testSourceDirs
1960+ from t in testTargetDirs
1961+ select new TestCaseData ( XFS . Path ( s ) , XFS . Path ( t ) ) ;
1962+ }
1963+ }
1964+
1965+ [ Test ]
1966+ [ TestCaseSource ( nameof ( Success_DirectoryMoveFromToPaths ) ) ]
1967+ public void Move_Directory_DoesNotThrow_When_Target_Directory_Parent_Exists (
1968+ string sourceDirName ,
1969+ string targetDirName )
1970+ {
1971+ // Arange
1972+ var fileSystem = new MockFileSystem ( ) ;
1973+ fileSystem . Directory . CreateDirectory ( sourceDirName ) ;
1974+
1975+ // Act
1976+ Assert . DoesNotThrow ( ( ) =>
1977+ fileSystem . Directory . Move ( sourceDirName , targetDirName ) ) ;
1978+
1979+ // Assert
1980+ Assert . IsTrue ( fileSystem . Directory . Exists ( targetDirName ) ) ;
1981+ Assert . IsFalse ( fileSystem . Directory . Exists ( sourceDirName ) ) ;
1982+ }
19061983 }
19071984}
0 commit comments