@@ -36,6 +36,10 @@ public InMemoryStorage(MockFileSystem fileSystem)
3636 CurrentDirectory = string . Empty . PrefixRoot ( _fileSystem ) ;
3737 DriveInfoMock mainDrive = DriveInfoMock . New ( CurrentDirectory , _fileSystem ) ;
3838 _drives . TryAdd ( mainDrive . GetName ( ) , mainDrive ) ;
39+ IStorageLocation rootLocation =
40+ InMemoryLocation . New ( _fileSystem , mainDrive , mainDrive . GetName ( ) ) ;
41+ _containers . TryAdd ( rootLocation , InMemoryContainer . NewDirectory ( rootLocation , _fileSystem ) ) ;
42+
3943 MainDrive = mainDrive ;
4044 }
4145
@@ -189,7 +193,7 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
189193 EnumerationOptions ? enumerationOptions = null )
190194 {
191195 ValidateExpression ( searchPattern ) ;
192- if ( ! _containers . TryGetValue ( location , out var parentContainer ) )
196+ if ( ! _containers . TryGetValue ( location , out IStorageContainer ? parentContainer ) )
193197 {
194198 throw ExceptionFactory . DirectoryNotFound ( location . FullPath ) ;
195199 }
@@ -227,11 +231,11 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
227231 }
228232
229233 if ( enumerationOptions . ReturnSpecialDirectories &&
230- type == FileSystemTypes . Directory )
234+ type == FileSystemTypes . Directory )
231235 {
232236 IStorageDrive ? drive = _fileSystem . Storage . GetDrive ( fullPath ) ;
233237 if ( drive == null &&
234- ! fullPath . IsUncPath ( _fileSystem ) )
238+ ! fullPath . IsUncPath ( _fileSystem ) )
235239 {
236240 drive = _fileSystem . Storage . MainDrive ;
237241 }
@@ -255,11 +259,12 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
255259
256260 foreach ( KeyValuePair < IStorageLocation , IStorageContainer > item in _containers
257261 . 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 ) ) )
260264 {
261265 if ( type . HasFlag ( item . Value . Type ) &&
262- IncludeItemInEnumeration ( item , fullPathWithoutTrailingSlash , enumerationOptions ) )
266+ IncludeItemInEnumeration ( item , fullPathWithoutTrailingSlash ,
267+ enumerationOptions ) )
263268 {
264269 string ? itemPath = item . Key . FullPath ;
265270 if ( itemPath . EndsWith ( _fileSystem . Path . DirectorySeparatorChar ) )
@@ -269,14 +274,14 @@ public IEnumerable<IStorageLocation> EnumerateLocations(
269274
270275 string name = _fileSystem . Execute . Path . GetFileName ( itemPath ) ;
271276 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 ) ) ) )
280285 {
281286 yield return item . Key ;
282287 }
@@ -346,8 +351,19 @@ public IEnumerable<IStorageDrive> GetDrives()
346351 drive = _fileSystem . Storage . MainDrive ;
347352 }
348353
349- return InMemoryLocation . New ( _fileSystem , drive , path . GetFullPathOrWhiteSpace ( _fileSystem ) ,
350- path ) ;
354+ string fullPath ;
355+ if ( path . IsUncPath ( _fileSystem ) &&
356+ _fileSystem . Execute is { IsNetFramework : true } or { IsWindows : false } &&
357+ path . LastIndexOf ( _fileSystem . Path . DirectorySeparatorChar ) <= 2 )
358+ {
359+ fullPath = path ;
360+ }
361+ else
362+ {
363+ fullPath = path . GetFullPathOrWhiteSpace ( _fileSystem ) ;
364+ }
365+
366+ return InMemoryLocation . New ( _fileSystem , drive , fullPath , path ) ;
351367 }
352368
353369 /// <inheritdoc cref="IStorage.GetOrAddDrive(string)" />
@@ -360,7 +376,14 @@ public IEnumerable<IStorageDrive> GetDrives()
360376 }
361377
362378 DriveInfoMock drive = DriveInfoMock . New ( driveName , _fileSystem ) ;
363- return _drives . GetOrAdd ( drive . GetName ( ) , _ => drive ) ;
379+ return _drives . GetOrAdd ( drive . GetName ( ) , _ =>
380+ {
381+ IStorageLocation rootLocation =
382+ InMemoryLocation . New ( _fileSystem , drive , drive . GetName ( ) ) ;
383+ _containers . TryAdd ( rootLocation ,
384+ InMemoryContainer . NewDirectory ( rootLocation , _fileSystem ) ) ;
385+ return drive ;
386+ } ) ;
364387 }
365388
366389 /// <inheritdoc cref="IStorage.GetOrCreateContainer" />
0 commit comments