@@ -44,7 +44,7 @@ public async Task GetPublicMetadata(ConfigurationManagerTheoryData<OpenIdConnect
4444 theoryData . DocumentRetriever ,
4545 theoryData . ConfigurationValidator ) ;
4646
47- TestUtilities . SetField ( configurationManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
47+ configurationManager . BackgroundTaskCancellationToken = cts . Token ;
4848
4949 var configuration = await configurationManager . GetConfigurationAsync ( CancellationToken . None ) ;
5050
@@ -203,7 +203,7 @@ private async Task FetchMetadataFailureTestBody()
203203
204204 var documentRetriever = new HttpDocumentRetriever ( HttpResponseMessageUtils . SetupHttpClientThatReturns ( "OpenIdConnectMetadata.json" , HttpStatusCode . NotFound ) ) ;
205205 var configManager = new ConfigurationManager < OpenIdConnectConfiguration > ( "OpenIdConnectMetadata.json" , new OpenIdConnectConfigurationRetriever ( ) , documentRetriever ) ;
206- TestUtilities . SetField ( configManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
206+ configManager . BackgroundTaskCancellationToken = cts . Token ;
207207
208208 // First time to fetch metadata
209209 try
@@ -252,7 +252,7 @@ public async Task VerifyInterlockGuardForGetConfigurationAsync()
252252 new OpenIdConnectConfigurationRetriever ( ) ,
253253 inMemoryDocumentRetriever ) ;
254254
255- TestUtilities . SetField ( configurationManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
255+ configurationManager . BackgroundTaskCancellationToken = cts . Token ;
256256
257257 OpenIdConnectConfiguration configuration = await configurationManager . GetConfigurationAsync ( ) ;
258258
@@ -305,7 +305,7 @@ public async Task BootstrapRefreshIntervalTest()
305305 documentRetriever )
306306 { RefreshInterval = TimeSpan . FromSeconds ( 2 ) } ;
307307
308- TestUtilities . SetField ( configManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
308+ configManager . BackgroundTaskCancellationToken = cts . Token ;
309309
310310 // ConfigurationManager._syncAfter is set to DateTimeOffset.MinValue on startup
311311 // If obtaining the metadata fails due to error, the value should not change
@@ -406,7 +406,7 @@ public void GetSets()
406406
407407 TestUtilities . WriteHeader ( $ "{ this } .GetSets", "GetSets" , true ) ;
408408
409- int ExpectedPropertyCount = 7 ;
409+ int ExpectedPropertyCount = 8 ;
410410 var configManager = new ConfigurationManager < OpenIdConnectConfiguration > ( "OpenIdConnectMetadata.json" , new OpenIdConnectConfigurationRetriever ( ) , new FileDocumentRetriever ( ) ) ;
411411 Type type = typeof ( ConfigurationManager < OpenIdConnectConfiguration > ) ;
412412 PropertyInfo [ ] properties = type . GetProperties ( ) ;
@@ -460,7 +460,6 @@ private async Task AutomaticRefreshIntervalBody(ConfigurationManagerTheoryData<O
460460
461461 theoryData . ConfigurationManager . MetadataAddress = theoryData . UpdatedMetadataAddress ;
462462 TestUtilities . SetField ( theoryData . ConfigurationManager , "_syncAfter" , theoryData . SyncAfter . UtcDateTime ) ;
463- TestUtilities . SetField ( theoryData . ConfigurationManager , "_BackgroundTaskCancellationToken" , theoryData . CancellationTokenSource . Token ) ;
464463 var updatedConfiguration = await theoryData . ConfigurationManager . GetConfigurationAsync ( CancellationToken . None ) ;
465464
466465 if ( ! blocking && theoryData . SyncAfter < DateTimeOffset . UtcNow . Add ( TimeSpan . FromMinutes ( 1 ) ) )
@@ -503,42 +502,57 @@ public static TheoryData<ConfigurationManagerTheoryData<OpenIdConnectConfigurati
503502 {
504503 var theoryData = new TheoryData < ConfigurationManagerTheoryData < OpenIdConnectConfiguration > > ( ) ;
505504
505+ var cts = new CancellationTokenSource ( ) ;
506+
506507 // Failing to get metadata returns existing.
507508 theoryData . Add ( new ConfigurationManagerTheoryData < OpenIdConnectConfiguration > ( "HttpFault_ReturnExisting" )
508509 {
509510 ConfigurationManager = new ConfigurationManager < OpenIdConnectConfiguration > (
510511 "AADCommonV1Json" ,
511512 new OpenIdConnectConfigurationRetriever ( ) ,
512- InMemoryDocumentRetriever ) ,
513- CancellationTokenSource = new ( ) ,
513+ InMemoryDocumentRetriever )
514+ {
515+ BackgroundTaskCancellationToken = cts . Token
516+ } ,
517+ CancellationTokenSource = cts ,
514518 ExpectedConfiguration = OpenIdConfigData . AADCommonV1Config ,
515519 ExpectedUpdatedConfiguration = OpenIdConfigData . AADCommonV1Config ,
516520 SyncAfter = DateTime . UtcNow - TimeSpan . FromDays ( 2 ) ,
517521 UpdatedMetadataAddress = "https://httpstat.us/429"
518522 } ) ;
519523
524+ cts = new ( ) ;
525+
520526 // AutomaticRefreshInterval interval should return same config.
521527 theoryData . Add ( new ConfigurationManagerTheoryData < OpenIdConnectConfiguration > ( "AutomaticRefreshIntervalNotHit" )
522528 {
523529 ConfigurationManager = new ConfigurationManager < OpenIdConnectConfiguration > (
524530 "AADCommonV1Json" ,
525531 new OpenIdConnectConfigurationRetriever ( ) ,
526- InMemoryDocumentRetriever ) ,
527- CancellationTokenSource = new ( ) ,
532+ InMemoryDocumentRetriever )
533+ {
534+ BackgroundTaskCancellationToken = cts . Token
535+ } ,
536+ CancellationTokenSource = cts ,
528537 ExpectedConfiguration = OpenIdConfigData . AADCommonV1Config ,
529538 ExpectedUpdatedConfiguration = OpenIdConfigData . AADCommonV1Config ,
530539 SyncAfter = DateTime . UtcNow + TimeSpan . FromDays ( 2 ) ,
531540 UpdatedMetadataAddress = "AADCommonV2Json"
532541 } ) ;
533542
543+ cts = new ( ) ;
544+
534545 // AutomaticRefreshInterval should pick up new bits.
535546 theoryData . Add ( new ConfigurationManagerTheoryData < OpenIdConnectConfiguration > ( "AutomaticRefreshIntervalHit" )
536547 {
537548 ConfigurationManager = new ConfigurationManager < OpenIdConnectConfiguration > (
538549 "AADCommonV1Json" ,
539550 new OpenIdConnectConfigurationRetriever ( ) ,
540- InMemoryDocumentRetriever ) ,
541- CancellationTokenSource = new ( ) ,
551+ InMemoryDocumentRetriever )
552+ {
553+ BackgroundTaskCancellationToken = cts . Token
554+ } ,
555+ CancellationTokenSource = cts ,
542556 ExpectedConfiguration = OpenIdConfigData . AADCommonV1Config ,
543557 ExpectedUpdatedConfiguration = OpenIdConfigData . AADCommonV2Config ,
544558 SyncAfter = DateTime . UtcNow ,
@@ -573,7 +587,6 @@ private async Task RequestRefreshBody(ConfigurationManagerTheoryData<OpenIdConne
573587
574588 var timeProvider = new FakeTimeProvider ( ) ;
575589 TestUtilities . SetField ( theoryData . ConfigurationManager , "_timeProvider" , timeProvider ) ;
576- TestUtilities . SetField ( theoryData . ConfigurationManager , "_BackgroundTaskCancellationToken" , theoryData . CancellationTokenSource . Token ) ;
577590
578591 // the first call to RequestRefresh will trigger a refresh with ConfigurationManager.RefreshInterval being ignored.
579592 // Testing RefreshInterval requires a two calls, the second call will trigger a refresh with ConfigurationManager.RefreshInterval being used.
@@ -611,14 +624,17 @@ public static TheoryData<ConfigurationManagerTheoryData<OpenIdConnectConfigurati
611624 {
612625 var theoryData = new TheoryData < ConfigurationManagerTheoryData < OpenIdConnectConfiguration > > ( ) ;
613626
614- // RefreshInterval set to 1 sec should return new config.
627+ var cts = new CancellationTokenSource ( ) ;
615628 theoryData . Add ( new ConfigurationManagerTheoryData < OpenIdConnectConfiguration > ( "RequestRefresh_TimeSpan_1000ms" )
616629 {
617630 ConfigurationManager = new ConfigurationManager < OpenIdConnectConfiguration > (
618631 "AADCommonV1Json" ,
619632 new OpenIdConnectConfigurationRetriever ( ) ,
620- InMemoryDocumentRetriever ) ,
621- CancellationTokenSource = new ( ) ,
633+ InMemoryDocumentRetriever )
634+ {
635+ BackgroundTaskCancellationToken = cts . Token
636+ } ,
637+ CancellationTokenSource = cts ,
622638 ExpectedConfiguration = OpenIdConfigData . AADCommonV1Config ,
623639 ExpectedUpdatedConfiguration = OpenIdConfigData . AADCommonV2Config ,
624640 RefreshInterval = TimeSpan . FromSeconds ( 1 ) ,
@@ -627,14 +643,17 @@ public static TheoryData<ConfigurationManagerTheoryData<OpenIdConnectConfigurati
627643 UpdatedMetadataAddress = "AADCommonV2Json"
628644 } ) ;
629645
630- // RefreshInterval set to TimeSpan.MaxValue should return same config.
646+ cts = new CancellationTokenSource ( ) ;
631647 theoryData . Add ( new ConfigurationManagerTheoryData < OpenIdConnectConfiguration > ( "RequestRefresh_TimeSpan_MaxValue" )
632648 {
633649 ConfigurationManager = new ConfigurationManager < OpenIdConnectConfiguration > (
634650 "AADCommonV1Json" ,
635651 new OpenIdConnectConfigurationRetriever ( ) ,
636- InMemoryDocumentRetriever ) ,
637- CancellationTokenSource = new ( ) ,
652+ InMemoryDocumentRetriever )
653+ {
654+ BackgroundTaskCancellationToken = cts . Token
655+ } ,
656+ CancellationTokenSource = cts ,
638657 ExpectedConfiguration = OpenIdConfigData . AADCommonV1Config ,
639658 ExpectedUpdatedConfiguration = OpenIdConfigData . AADCommonV1Config ,
640659 RefreshInterval = TimeSpan . MaxValue ,
@@ -643,14 +662,17 @@ public static TheoryData<ConfigurationManagerTheoryData<OpenIdConnectConfigurati
643662 UpdatedMetadataAddress = "AADCommonV2Json"
644663 } ) ;
645664
646- // First RequestRefresh should pickup new config
665+ cts = new CancellationTokenSource ( ) ;
647666 theoryData . Add ( new ConfigurationManagerTheoryData < OpenIdConnectConfiguration > ( "RequestRefresh_FirstRefresh" )
648667 {
649668 ConfigurationManager = new ConfigurationManager < OpenIdConnectConfiguration > (
650669 "AADCommonV1Json" ,
651670 new OpenIdConnectConfigurationRetriever ( ) ,
652- InMemoryDocumentRetriever ) ,
653- CancellationTokenSource = new ( ) ,
671+ InMemoryDocumentRetriever )
672+ {
673+ BackgroundTaskCancellationToken = cts . Token
674+ } ,
675+ CancellationTokenSource = cts ,
654676 ExpectedConfiguration = OpenIdConfigData . AADCommonV1Config ,
655677 ExpectedUpdatedConfiguration = OpenIdConfigData . AADCommonV2Config ,
656678 SleepTimeInMs = 1000 ,
@@ -751,7 +773,7 @@ private async Task CheckSyncAfterBody(bool blocking = false)
751773 new OpenIdConnectConfigurationRetriever ( ) ,
752774 docRetriever ) ;
753775
754- TestUtilities . SetField ( configManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
776+ configManager . BackgroundTaskCancellationToken = cts . Token ;
755777
756778 AutoResetEvent resetEvent = SetupResetEvent ( configManager , blocking ) ;
757779
@@ -833,7 +855,7 @@ private async Task GetConfigurationBody()
833855 new OpenIdConnectConfigurationRetriever ( ) ,
834856 docRetriever ) ;
835857
836- TestUtilities . SetField ( configManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
858+ configManager . BackgroundTaskCancellationToken = cts . Token ;
837859
838860 var configuration = await configManager . GetConfigurationAsync ( CancellationToken . None ) ;
839861
@@ -974,7 +996,7 @@ private async Task RequestRefresh_RespectsRefreshInterval_Body(bool blocking = f
974996 docRetriever ) ;
975997
976998 TestUtilities . SetField ( configManager , "_timeProvider" , timeProvider ) ;
977- TestUtilities . SetField ( configManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
999+ configManager . BackgroundTaskCancellationToken = cts . Token ;
9781000
9791001 var resetEvent = SetupResetEvent ( configManager , blocking ) ;
9801002
@@ -1071,7 +1093,7 @@ private async Task GetConfigurationAsync_RespectsRefreshIntervalBody(bool blocki
10711093 docRetriever ) ;
10721094
10731095 TestUtilities . SetField ( configManager , "_timeProvider" , timeProvider ) ;
1074- TestUtilities . SetField ( configManager , "_BackgroundTaskCancellationToken" , cts . Token ) ;
1096+ configManager . BackgroundTaskCancellationToken = cts . Token ;
10751097
10761098 TimeSpan advanceInterval = BaseConfigurationManager . DefaultAutomaticRefreshInterval . Add ( TimeSpan . FromSeconds ( configManager . AutomaticRefreshInterval . TotalSeconds ) ) ;
10771099
@@ -1138,9 +1160,10 @@ private async Task ValidateOIDCConfigurationBody(ConfigurationManagerTheoryData<
11381160 theoryData . MetadataAddress ,
11391161 theoryData . ConfigurationRetriever ,
11401162 theoryData . DocumentRetriever ,
1141- theoryData . ConfigurationValidator ) ;
1142-
1143- TestUtilities . SetField ( configurationManager , "_BackgroundTaskCancellationToken" , theoryData . CancellationTokenSource . Token ) ;
1163+ theoryData . ConfigurationValidator )
1164+ {
1165+ BackgroundTaskCancellationToken = theoryData . CancellationTokenSource . Token
1166+ } ;
11441167
11451168 var resetEvent = SetupResetEvent ( configurationManager , blocking ) ;
11461169
0 commit comments