@@ -383,6 +383,15 @@ public async Task SnapshotReferenceRegisteredWithRefreshAllFalse()
383383 mockClient . Setup ( c => c . GetConfigurationSettingsForSnapshotAsync ( "snapshot1" , It . IsAny < CancellationToken > ( ) ) )
384384 . Returns ( new MockAsyncPageable ( new List < ConfigurationSetting > { _settingInSnapshot1 } ) ) ;
385385
386+ // Add mock for snapshot2 since the updated reference points to it
387+ var realSnapshot2 = new ConfigurationSnapshot ( settingsToInclude ) { SnapshotComposition = SnapshotComposition . Key } ;
388+
389+ mockClient . Setup ( c => c . GetSnapshotAsync ( "snapshot2" , It . IsAny < IEnumerable < SnapshotFields > > ( ) , It . IsAny < CancellationToken > ( ) ) )
390+ . ReturnsAsync ( Response . FromValue ( realSnapshot2 , mockResponse . Object ) ) ;
391+
392+ mockClient . Setup ( c => c . GetConfigurationSettingsForSnapshotAsync ( "snapshot2" , It . IsAny < CancellationToken > ( ) ) )
393+ . Returns ( new MockAsyncPageable ( new List < ConfigurationSetting > { _settingInSnapshot2 } ) ) ;
394+
386395 mockClient . Setup ( c => c . GetConfigurationSettingAsync ( "SnapshotRef1" , It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
387396 . ReturnsAsync ( ( ) =>
388397 {
@@ -538,5 +547,69 @@ public async Task SnapshotReferenceRegisteredWithoutRefreshAllParameter_StillTri
538547
539548 Assert . True ( refreshAllTriggered , "RefreshAll should be triggered for snapshot references even without explicit refreshAll parameter" ) ;
540549 }
550+
551+ // Scenario D: Register("SnapshotRef1") but not in Select() → Should resolve and load settings during LoadKeyValuesRegisteredForRefresh
552+ [ Fact ]
553+ public void SnapshotReferenceRegisteredForRefreshButNotInSelect ( )
554+ {
555+ IConfigurationRefresher refresher = null ;
556+ TimeSpan refreshInterval = TimeSpan . FromSeconds ( 1 ) ;
557+
558+ var mockResponse = new Mock < Response > ( ) ;
559+ var mockClient = new Mock < ConfigurationClient > ( MockBehavior . Strict ) ;
560+
561+ // Only return regular key-value in initial load (snapshot reference not selected)
562+ mockClient . Setup ( c => c . GetConfigurationSettingsAsync ( It . IsAny < SettingSelector > ( ) , It . IsAny < CancellationToken > ( ) ) )
563+ . Returns ( new MockAsyncPageable ( new List < ConfigurationSetting > { _regularKeyValue } ) ) ;
564+
565+ // Setup mocks for when registered key is loaded during refresh initialization
566+ var settingsToInclude = new List < ConfigurationSettingsFilter > { new ConfigurationSettingsFilter ( "*" ) } ;
567+ var realSnapshot = new ConfigurationSnapshot ( settingsToInclude ) { SnapshotComposition = SnapshotComposition . Key } ;
568+
569+ mockClient . Setup ( c => c . GetSnapshotAsync ( "snapshot1" , It . IsAny < IEnumerable < SnapshotFields > > ( ) , It . IsAny < CancellationToken > ( ) ) )
570+ . ReturnsAsync ( Response . FromValue ( realSnapshot , mockResponse . Object ) ) ;
571+
572+ mockClient . Setup ( c => c . GetConfigurationSettingsForSnapshotAsync ( "snapshot1" , It . IsAny < CancellationToken > ( ) ) )
573+ . Returns ( new MockAsyncPageable ( new List < ConfigurationSetting > { _settingInSnapshot1 } ) ) ;
574+
575+ // Mock the GetConfigurationSettingAsync call for the registered snapshot reference
576+ mockClient . Setup ( c => c . GetConfigurationSettingAsync ( "SnapshotRef1" , It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
577+ . ReturnsAsync ( ( ) => Response . FromValue ( _snapshotReference1 , mockResponse . Object ) ) ;
578+
579+ mockClient . Setup ( c => c . GetConfigurationSettingAsync ( It . IsAny < ConfigurationSetting > ( ) , It . IsAny < bool > ( ) , It . IsAny < CancellationToken > ( ) ) )
580+ . ReturnsAsync ( ( ConfigurationSetting setting , bool onlyIfChanged , CancellationToken token ) =>
581+ {
582+ // Simulates no changes
583+ return Response . FromValue ( setting , new MockResponse ( 304 ) ) ;
584+ } ) ;
585+
586+ var configuration = new ConfigurationBuilder ( )
587+ . AddAzureAppConfiguration ( options =>
588+ {
589+ options . ClientManager = TestHelpers . CreateMockedConfigurationClientManager ( mockClient . Object ) ;
590+ options . ConfigureRefresh ( refreshOptions =>
591+ {
592+ // Register snapshot reference for monitoring but not in Select()
593+ refreshOptions . Register ( "SnapshotRef1" , refreshAll : false )
594+ . SetRefreshInterval ( refreshInterval ) ;
595+ } ) ;
596+ refresher = options . GetRefresher ( ) ;
597+ } )
598+ . Build ( ) ;
599+
600+ // Verify that snapshot reference was resolved
601+ Assert . Equal ( "ValueFromSnapshot" , configuration [ "TestKey1" ] ) ;
602+ Assert . Equal ( "RegularValue" , configuration [ "RegularKey" ] ) ;
603+
604+ // Snapshot reference itself should not be in config
605+ Assert . Null ( configuration [ "SnapshotRef1" ] ) ;
606+
607+ // Verify the snapshot was resolved during registration
608+ mockClient . Verify ( c => c . GetSnapshotAsync ( "snapshot1" , It . IsAny < IEnumerable < SnapshotFields > > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
609+ mockClient . Verify ( c => c . GetConfigurationSettingsForSnapshotAsync ( "snapshot1" , It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
610+
611+ // Verify snapshot reference was loaded for monitoring
612+ mockClient . Verify ( c => c . GetConfigurationSettingAsync ( "SnapshotRef1" , It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
613+ }
541614 }
542615}
0 commit comments