@@ -32,7 +32,7 @@ public MockDirectory(IMockFileDataAccessor mockFileDataAccessor, FileBase fileBa
3232
3333 public override DirectoryInfoBase CreateDirectory ( string path )
3434 {
35- return CreateDirectoryInternal ( path , null ) ;
35+ return CreateDirectoryInternal ( path , new DirectorySecurity ( ) ) ;
3636 }
3737
3838#if NET40
@@ -61,6 +61,7 @@ private DirectoryInfoBase CreateDirectoryInternal(string path, DirectorySecurity
6161 }
6262
6363 var created = new MockDirectoryInfo ( mockFileDataAccessor , path ) ;
64+ created . SetAccessControl ( directorySecurity ) ;
6465 return created ;
6566 }
6667
@@ -93,7 +94,6 @@ public override bool Exists(string path)
9394 try
9495 {
9596 path = EnsurePathEndsWithDirectorySeparator ( path ) ;
96-
9797 path = mockFileDataAccessor . Path . GetFullPath ( path ) ;
9898 return mockFileDataAccessor . AllDirectories . Any ( p => p . Equals ( path , StringComparison . OrdinalIgnoreCase ) ) ;
9999 }
@@ -104,19 +104,21 @@ public override bool Exists(string path)
104104 }
105105
106106 public override DirectorySecurity GetAccessControl ( string path )
107- {
108- // First crude implementation to avoid NotImplementedException
109- if ( Exists ( path ) )
107+ {
108+ mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( path , "path" ) ;
109+ path = EnsurePathEndsWithDirectorySeparator ( path ) ;
110+
111+ if ( ! mockFileDataAccessor . Directory . Exists ( path ) )
110112 {
111- return new DirectorySecurity ( ) ;
113+ throw new DirectoryNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_PART_OF_PATH_EXCEPTION" ) , path ) ) ;
112114 }
113115
114- throw new DirectoryNotFoundException ( path ) ;
116+ var directoryData = ( MockDirectoryData ) mockFileDataAccessor . GetFile ( path ) ;
117+ return directoryData . AccessControl ;
115118 }
116119
117120 public override DirectorySecurity GetAccessControl ( string path , AccessControlSections includeSections )
118121 {
119- // First crude implementation to avoid NotImplementedException
120122 return GetAccessControl ( path ) ;
121123 }
122124
@@ -376,7 +378,16 @@ public override void Move(string sourceDirName, string destDirName)
376378
377379 public override void SetAccessControl ( string path , DirectorySecurity directorySecurity )
378380 {
379- throw new NotImplementedException ( StringResources . Manager . GetString ( "NOT_IMPLEMENTED_EXCEPTION" ) ) ;
381+ mockFileDataAccessor . PathVerifier . IsLegalAbsoluteOrRelative ( path , "path" ) ;
382+ path = EnsurePathEndsWithDirectorySeparator ( path ) ;
383+
384+ if ( ! mockFileDataAccessor . Directory . Exists ( path ) )
385+ {
386+ throw new DirectoryNotFoundException ( string . Format ( CultureInfo . InvariantCulture , StringResources . Manager . GetString ( "COULD_NOT_FIND_PART_OF_PATH_EXCEPTION" ) , path ) ) ;
387+ }
388+
389+ var directoryData = ( MockDirectoryData ) mockFileDataAccessor . GetFile ( path ) ;
390+ directoryData . AccessControl = directorySecurity ;
380391 }
381392
382393 public override void SetCreationTime ( string path , DateTime creationTime )
0 commit comments