@@ -12,6 +12,11 @@ public sealed class PrefixedFileProviderTests : AbstractFileProviderTests
1212 . GetMethod ( "ResolveGlobFilter" , BindingFlags . Static | BindingFlags . NonPublic ) !
1313 . CreateDelegate < Func < string , string , string ? > > ( ) ;
1414
15+ private static readonly Func < string , string , string ? > s_resolvePath =
16+ typeof ( PrefixedFileProvider )
17+ . GetMethod ( "ResolvePath" , BindingFlags . Static | BindingFlags . NonPublic ) !
18+ . CreateDelegate < Func < string , string , string ? > > ( ) ;
19+
1520 private readonly TempFileStorage _storage = new TempFileStorage ( ) ;
1621
1722 protected override IFileProvider GetFileProvider ( ) =>
@@ -37,4 +42,52 @@ protected override DirectoryInfo GetDirectoryInfo() =>
3742 [ TestCase ( "/modules/profile/assets" , "/*.js" , ExpectedResult = null ) ]
3843 public string ? ResolveGlobFilter ( string prefix , string filter ) =>
3944 s_resolveGlobFilter ( prefix , filter ) ;
45+
46+ [ TestCase ( "/" , "/" , ExpectedResult = "/" ) ]
47+ [ TestCase ( "/" , "/foo" , ExpectedResult = "/foo" ) ]
48+ [ TestCase ( "/" , "/a/b/c" , ExpectedResult = "/a/b/c" ) ]
49+
50+ [ TestCase ( "/a/b" , "/a/b" , ExpectedResult = "/" ) ]
51+
52+ [ TestCase ( "/a/b" , "/a/b/c" , ExpectedResult = "/c" ) ]
53+ [ TestCase ( "/a/b" , "/a/b/c/d" , ExpectedResult = "/c/d" ) ]
54+
55+ [ TestCase ( "/a/b" , "/a/bc" , ExpectedResult = null ) ]
56+
57+ [ TestCase ( "/a/b" , "/a/c" , ExpectedResult = null ) ]
58+ [ TestCase ( "/a/b" , "/a" , ExpectedResult = null ) ]
59+ public string ? ResolvePath ( string prefix , string path ) =>
60+ s_resolvePath ( prefix , path ) ;
61+
62+ [ Test ]
63+ public void GetFileInfo_RootPrefix_DelegatesToInnerProvider ( )
64+ {
65+ using var provider = new PrefixedFileProvider ( "/" ,
66+ new PhysicalFileProvider ( _storage . Root , ExclusionFilters . None ) ) ;
67+
68+ var file = provider . GetFileInfo ( "/project/README.md" ) ;
69+ Assert . That ( file . Exists , Is . True ) ;
70+ Assert . That ( file . IsDirectory , Is . False ) ;
71+ }
72+
73+ [ Test ]
74+ public void GetDirectoryContents_RootPrefix_DelegatesToInnerProvider ( )
75+ {
76+ using var provider = new PrefixedFileProvider ( "/" ,
77+ new PhysicalFileProvider ( _storage . Root , ExclusionFilters . None ) ) ;
78+
79+ var contents = provider . GetDirectoryContents ( "/project/docs" ) ;
80+ Assert . That ( contents . Exists , Is . True ) ;
81+ Assert . That ( contents . Any ( ) , Is . True ) ;
82+ }
83+
84+ [ Test ]
85+ public void GetFileInfo_RootPrefix_MissingFile_ReturnsNotFound ( )
86+ {
87+ using var provider = new PrefixedFileProvider ( "/" ,
88+ new PhysicalFileProvider ( _storage . Root , ExclusionFilters . None ) ) ;
89+
90+ var file = provider . GetFileInfo ( "/project/nonexistent.txt" ) ;
91+ Assert . That ( file . Exists , Is . False ) ;
92+ }
4093}
0 commit comments