@@ -36,6 +36,10 @@ public InMemoryStorage(MockFileSystem fileSystem)
36
36
CurrentDirectory = string . Empty . PrefixRoot ( _fileSystem ) ;
37
37
DriveInfoMock mainDrive = DriveInfoMock . New ( CurrentDirectory , _fileSystem ) ;
38
38
_drives . TryAdd ( mainDrive . GetName ( ) , mainDrive ) ;
39
+ IStorageLocation rootLocation =
40
+ InMemoryLocation . New ( _fileSystem , mainDrive , mainDrive . GetName ( ) ) ;
41
+ _containers . TryAdd ( rootLocation , InMemoryContainer . NewDirectory ( rootLocation , _fileSystem ) ) ;
42
+
39
43
MainDrive = mainDrive ;
40
44
}
41
45
@@ -189,7 +193,7 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
189
193
EnumerationOptions ? enumerationOptions = null )
190
194
{
191
195
ValidateExpression ( searchPattern ) ;
192
- if ( ! _containers . TryGetValue ( location , out var parentContainer ) )
196
+ if ( ! _containers . TryGetValue ( location , out IStorageContainer ? parentContainer ) )
193
197
{
194
198
throw ExceptionFactory . DirectoryNotFound ( location . FullPath ) ;
195
199
}
@@ -227,11 +231,11 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
227
231
}
228
232
229
233
if ( enumerationOptions . ReturnSpecialDirectories &&
230
- type == FileSystemTypes . Directory )
234
+ type == FileSystemTypes . Directory )
231
235
{
232
236
IStorageDrive ? drive = _fileSystem . Storage . GetDrive ( fullPath ) ;
233
237
if ( drive == null &&
234
- ! fullPath . IsUncPath ( _fileSystem ) )
238
+ ! fullPath . IsUncPath ( _fileSystem ) )
235
239
{
236
240
drive = _fileSystem . Storage . MainDrive ;
237
241
}
@@ -255,11 +259,12 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
255
259
256
260
foreach ( KeyValuePair < IStorageLocation , IStorageContainer > item in _containers
257
261
. Where ( x => x . Key . FullPath . StartsWith ( fullPath ,
258
- _fileSystem . Execute . StringComparisonMode ) &&
259
- ! x . Key . Equals ( location ) ) )
262
+ _fileSystem . Execute . StringComparisonMode ) &&
263
+ ! x . Key . Equals ( location ) ) )
260
264
{
261
265
if ( type . HasFlag ( item . Value . Type ) &&
262
- IncludeItemInEnumeration ( item , fullPathWithoutTrailingSlash , enumerationOptions ) )
266
+ IncludeItemInEnumeration ( item , fullPathWithoutTrailingSlash ,
267
+ enumerationOptions ) )
263
268
{
264
269
string ? itemPath = item . Key . FullPath ;
265
270
if ( itemPath . EndsWith ( _fileSystem . Path . DirectorySeparatorChar ) )
@@ -269,14 +274,14 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
269
274
270
275
string name = _fileSystem . Execute . Path . GetFileName ( itemPath ) ;
271
276
if ( EnumerationOptionsHelper . MatchesPattern (
272
- _fileSystem . Execute ,
273
- enumerationOptions ,
274
- name ,
275
- searchPattern ) ||
276
- ( _fileSystem . Execute . IsNetFramework &&
277
- SearchPatternMatchesFileExtensionOnNetFramework (
278
- searchPattern ,
279
- _fileSystem . Execute . Path . GetExtension ( name ) ) ) )
277
+ _fileSystem . Execute ,
278
+ enumerationOptions ,
279
+ name ,
280
+ searchPattern ) ||
281
+ ( _fileSystem . Execute . IsNetFramework &&
282
+ SearchPatternMatchesFileExtensionOnNetFramework (
283
+ searchPattern ,
284
+ _fileSystem . Execute . Path . GetExtension ( name ) ) ) )
280
285
{
281
286
yield return item . Key ;
282
287
}
@@ -360,7 +365,11 @@ public IEnumerable<IStorageDrive> GetDrives()
360
365
}
361
366
362
367
DriveInfoMock drive = DriveInfoMock . New ( driveName , _fileSystem ) ;
363
- return _drives . GetOrAdd ( drive . GetName ( ) , _ => drive ) ;
368
+ return _drives . GetOrAdd ( drive . GetName ( ) , _ =>
369
+ {
370
+ GetOrCreateContainer ( GetLocation ( drive . GetName ( ) ) , InMemoryContainer . NewDirectory ) ;
371
+ return drive ;
372
+ } ) ;
364
373
}
365
374
366
375
/// <inheritdoc cref="IStorage.GetOrCreateContainer" />
0 commit comments