@@ -178,6 +178,97 @@ public async Task OnConfigLoaded_DoesNotRewriteYamlFile()
178178 }
179179 }
180180
181+ [ Fact ]
182+ public async Task OnConfigReady_ReceivesManagerWithHookAdjustedValues ( )
183+ {
184+ using var temp = new TempDirectory ( ) ;
185+ await using var bootstrap = NewBootstrap ( temp . Path ) ;
186+ var observedLimit = 0 ;
187+ var invocations = 0 ;
188+ bootstrap . ConfigureServices ( c =>
189+ {
190+ c . RegisterConfigSection ( "fakeSection" , static ( ) => new FakeSectionConfig ( ) , 0 ) ;
191+ return c ;
192+ } ) ;
193+ bootstrap . OnConfigLoaded < FakeSectionConfig > ( f => f . Limit = 42 ) ;
194+ bootstrap . OnConfigReady ( cfg =>
195+ {
196+ invocations ++ ;
197+ observedLimit = cfg . GetConfig < FakeSectionConfig > ( ) . Limit ;
198+ } ) ;
199+
200+ await bootstrap . StartAsync ( ) ;
201+ try
202+ {
203+ Assert . True ( invocations >= 1 ) ;
204+ Assert . Equal ( 42 , observedLimit ) ;
205+ }
206+ finally
207+ {
208+ await bootstrap . StopAsync ( ) ;
209+ }
210+ }
211+
212+ [ Fact ]
213+ public async Task OnConfigReady_MultipleCallbacks_RunInOrder ( )
214+ {
215+ using var temp = new TempDirectory ( ) ;
216+ await using var bootstrap = NewBootstrap ( temp . Path ) ;
217+ var order = new List < string > ( ) ;
218+ bootstrap . OnConfigReady ( _ => order . Add ( "a" ) ) ;
219+ bootstrap . OnConfigReady ( _ => order . Add ( "b" ) ) ;
220+
221+ await bootstrap . StartAsync ( ) ;
222+ try
223+ {
224+ Assert . True ( order . Count >= 2 ) ;
225+ Assert . Equal ( "a" , order [ 0 ] ) ;
226+ Assert . Equal ( "b" , order [ 1 ] ) ;
227+ }
228+ finally
229+ {
230+ await bootstrap . StopAsync ( ) ;
231+ }
232+ }
233+
234+ [ Fact ]
235+ public async Task OnConfigReady_WithoutTypedHooks_StillRuns ( )
236+ {
237+ using var temp = new TempDirectory ( ) ;
238+ await using var bootstrap = NewBootstrap ( temp . Path ) ;
239+ var composed = string . Empty ;
240+ bootstrap . OnConfigReady ( cfg => composed = cfg . Compose ( ) ) ;
241+
242+ await bootstrap . StartAsync ( ) ;
243+ try
244+ {
245+ Assert . Contains ( "logger" , composed , StringComparison . Ordinal ) ;
246+ }
247+ finally
248+ {
249+ await bootstrap . StopAsync ( ) ;
250+ }
251+ }
252+
253+ [ Fact ]
254+ public async Task OnConfigReady_AfterStart_Throws ( )
255+ {
256+ using var temp = new TempDirectory ( ) ;
257+ await using var bootstrap = NewBootstrap ( temp . Path ) ;
258+
259+ await bootstrap . StartAsync ( ) ;
260+ try
261+ {
262+ Assert . Throws < InvalidOperationException > (
263+ ( ) => bootstrap . OnConfigReady ( _ => { } )
264+ ) ;
265+ }
266+ finally
267+ {
268+ await bootstrap . StopAsync ( ) ;
269+ }
270+ }
271+
181272 private static SquidStdBootstrap NewBootstrap ( string root )
182273 => SquidStdBootstrap . Create ( new SquidStdOptions { ConfigName = "app" , RootDirectory = root } ) ;
183274}
0 commit comments