@@ -24,14 +24,18 @@ public MockFileSystem(IDictionary<string, MockFileData> files, string currentDir
2424 {
2525 currentDirectory = XFS . Path ( DEFAULT_CURRENT_DIRECTORY ) ;
2626 }
27+ else if ( ! System . IO . Path . IsPathRooted ( currentDirectory ) )
28+ {
29+ throw new ArgumentException ( "Current directory needs to be rooted." , nameof ( currentDirectory ) ) ;
30+ }
2731
2832 var defaultTempDirectory = XFS . Path ( TEMP_DIRECTORY ) ;
2933
3034 StringOperations = new StringOperations ( XFS . IsUnixPlatform ( ) ) ;
3135 pathVerifier = new PathVerifier ( this ) ;
3236 this . files = new Dictionary < string , MockFileData > ( StringOperations . Comparer ) ;
3337
34- Path = new MockPath ( this , defaultTempDirectory ) ;
38+ Path = new MockPath ( this , defaultTempDirectory ) ;
3539 File = new MockFile ( this ) ;
3640 Directory = new MockDirectory ( this , currentDirectory ) ;
3741 FileInfo = new MockFileInfoFactory ( this ) ;
@@ -53,7 +57,7 @@ public MockFileSystem(IDictionary<string, MockFileData> files, string currentDir
5357 AddDirectory ( currentDirectory ) ;
5458 }
5559
56- if ( ! FileExists ( defaultTempDirectory ) )
60+ if ( ! FileExists ( defaultTempDirectory ) )
5761 {
5862 AddDirectory ( defaultTempDirectory ) ;
5963 }
@@ -77,7 +81,7 @@ private string FixPath(string path, bool checkCaps = false)
7781 {
7882 throw new ArgumentNullException ( nameof ( path ) , StringResources . Manager . GetString ( "VALUE_CANNOT_BE_NULL" ) ) ;
7983 }
80-
84+
8185 var pathSeparatorFixed = path . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ;
8286 var fullPath = Path . GetFullPath ( pathSeparatorFixed ) ;
8387
@@ -159,7 +163,7 @@ public void AddDirectory(string path)
159163 {
160164 if ( FileExists ( fixedPath ) &&
161165 ( GetFile ( fixedPath ) . Attributes & FileAttributes . ReadOnly ) == FileAttributes . ReadOnly )
162- throw CommonExceptions . AccessDenied ( fixedPath ) ;
166+ throw CommonExceptions . AccessDenied ( fixedPath ) ;
163167
164168 var lastIndex = 0 ;
165169 var isUnc =
@@ -238,7 +242,7 @@ public void MoveDirectory(string sourcePath, string destPath)
238242 . Where ( p => StringOperations . StartsWith ( p , sourcePath ) )
239243 . ToList ( ) ;
240244
241- foreach ( var path in affectedPaths )
245+ foreach ( var path in affectedPaths )
242246 {
243247 var newPath = StringOperations . Replace ( path , sourcePath , destPath ) ;
244248 files [ newPath ] = files [ path ] ;
0 commit comments