@@ -20,9 +20,7 @@ public class AzureADAuthenticationBuilderExtensionsTests
2020 public void AddAzureAD_AddsAllAuthenticationHandlers ( )
2121 {
2222 // Arrange
23- var services = new ServiceCollection ( ) ;
24- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
25- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
23+ var services = GenerateServicesForTest ( ) ;
2624
2725 // Act
2826 services . AddAuthentication ( )
@@ -39,8 +37,7 @@ public void AddAzureAD_AddsAllAuthenticationHandlers()
3937 public void AddAzureAD_ConfiguresAllOptions ( )
4038 {
4139 // Arrange
42- var services = new ServiceCollection ( ) ;
43- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
40+ var services = GenerateServicesForTest ( ) ;
4441
4542 // Act
4643 services . AddAuthentication ( )
@@ -89,8 +86,7 @@ public void AddAzureAD_ConfiguresAllOptions()
8986 public void AddAzureAD_AllowsOverridingCookiesAndOpenIdConnectSettings ( )
9087 {
9188 // Arrange
92- var services = new ServiceCollection ( ) ;
93- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
89+ var services = GenerateServicesForTest ( ) ;
9490
9591 // Act
9692 services . AddAuthentication ( )
@@ -134,8 +130,7 @@ public void AddAzureAD_AllowsOverridingCookiesAndOpenIdConnectSettings()
134130 public void AddAzureAD_RegisteringAddCookiesAndAddOpenIdConnectHasNoImpactOnAzureAAExtensions ( )
135131 {
136132 // Arrange
137- var services = new ServiceCollection ( ) ;
138- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
133+ var services = GenerateServicesForTest ( ) ;
139134
140135 // Act
141136 services . AddAuthentication ( )
@@ -181,8 +176,7 @@ public void AddAzureAD_RegisteringAddCookiesAndAddOpenIdConnectHasNoImpactOnAzur
181176 public void AddAzureAD_ThrowsForDuplicatedSchemes ( )
182177 {
183178 // Arrange
184- var services = new ServiceCollection ( ) ;
185- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
179+ var services = GenerateServicesForTest ( ) ;
186180
187181 services . AddAuthentication ( )
188182 . AddAzureAD ( o => { } )
@@ -202,8 +196,7 @@ public void AddAzureAD_ThrowsForDuplicatedSchemes()
202196 public void AddAzureAD_ThrowsWhenOpenIdSchemeIsAlreadyInUse ( )
203197 {
204198 // Arrange
205- var services = new ServiceCollection ( ) ;
206- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
199+ var services = GenerateServicesForTest ( ) ;
207200
208201 services . AddAuthentication ( )
209202 . AddAzureAD ( o => { } )
@@ -226,8 +219,7 @@ public void AddAzureAD_ThrowsWhenOpenIdSchemeIsAlreadyInUse()
226219 public void AddAzureAD_ThrowsWhenCookieSchemeIsAlreadyInUse ( )
227220 {
228221 // Arrange
229- var services = new ServiceCollection ( ) ;
230- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
222+ var services = GenerateServicesForTest ( ) ;
231223
232224 services . AddAuthentication ( )
233225 . AddAzureAD ( o => { } )
@@ -250,8 +242,7 @@ public void AddAzureAD_ThrowsWhenCookieSchemeIsAlreadyInUse()
250242 public void AddAzureAD_ThrowsWhenInstanceIsNotSet ( )
251243 {
252244 // Arrange
253- var services = new ServiceCollection ( ) ;
254- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
245+ var services = GenerateServicesForTest ( ) ;
255246
256247 services . AddAuthentication ( )
257248 . AddAzureAD ( o => { } ) ;
@@ -271,8 +262,7 @@ public void AddAzureAD_ThrowsWhenInstanceIsNotSet()
271262 [ Fact ]
272263 public void AddAzureAD_SkipsOptionsValidationForNonAzureCookies ( )
273264 {
274- var services = new ServiceCollection ( ) ;
275- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
265+ var services = GenerateServicesForTest ( ) ;
276266
277267 services . AddAuthentication ( )
278268 . AddAzureAD ( o => { } )
@@ -288,9 +278,7 @@ public void AddAzureAD_SkipsOptionsValidationForNonAzureCookies()
288278 public void AddAzureADBearer_AddsAllAuthenticationHandlers ( )
289279 {
290280 // Arrange
291- var services = new ServiceCollection ( ) ;
292- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
293- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
281+ var services = GenerateServicesForTest ( ) ;
294282
295283 // Act
296284 services . AddAuthentication ( )
@@ -306,9 +294,7 @@ public void AddAzureADBearer_AddsAllAuthenticationHandlers()
306294 public void AddAzureADBearer_ConfiguresAllOptions ( )
307295 {
308296 // Arrange
309- var services = new ServiceCollection ( ) ;
310- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
311- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
297+ var services = GenerateServicesForTest ( ) ;
312298
313299 // Act
314300 services . AddAuthentication ( )
@@ -342,9 +328,7 @@ public void AddAzureADBearer_ConfiguresAllOptions()
342328 public void AddAzureADBearer_CanOverrideJwtBearerOptionsConfiguration ( )
343329 {
344330 // Arrange
345- var services = new ServiceCollection ( ) ;
346- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
347- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
331+ var services = GenerateServicesForTest ( ) ;
348332
349333 // Act
350334 services . AddAuthentication ( )
@@ -376,9 +360,7 @@ public void AddAzureADBearer_CanOverrideJwtBearerOptionsConfiguration()
376360 public void AddAzureADBearer_RegisteringJwtBearerHasNoImpactOnAzureAAExtensions ( )
377361 {
378362 // Arrange
379- var services = new ServiceCollection ( ) ;
380- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
381- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
363+ var services = GenerateServicesForTest ( ) ;
382364
383365 // Act
384366 services . AddAuthentication ( )
@@ -411,8 +393,7 @@ public void AddAzureADBearer_RegisteringJwtBearerHasNoImpactOnAzureAAExtensions(
411393 public void AddAzureADBearer_ThrowsForDuplicatedSchemes ( )
412394 {
413395 // Arrange
414- var services = new ServiceCollection ( ) ;
415- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
396+ var services = GenerateServicesForTest ( ) ;
416397
417398 services . AddAuthentication ( )
418399 . AddAzureADBearer ( o => { } )
@@ -432,8 +413,7 @@ public void AddAzureADBearer_ThrowsForDuplicatedSchemes()
432413 public void AddAzureADBearer_ThrowsWhenBearerSchemeIsAlreadyInUse ( )
433414 {
434415 // Arrange
435- var services = new ServiceCollection ( ) ;
436- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
416+ var services = GenerateServicesForTest ( ) ;
437417
438418 services . AddAuthentication ( )
439419 . AddAzureADBearer ( o => { } )
@@ -456,8 +436,7 @@ public void AddAzureADBearer_ThrowsWhenBearerSchemeIsAlreadyInUse()
456436 public void AddAzureADBearer_ThrowsWhenInstanceIsNotSet ( )
457437 {
458438 // Arrange
459- var services = new ServiceCollection ( ) ;
460- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
439+ var services = GenerateServicesForTest ( ) ;
461440
462441 services . AddAuthentication ( )
463442 . AddAzureADBearer ( o => { } ) ;
@@ -477,9 +456,7 @@ public void AddAzureADBearer_ThrowsWhenInstanceIsNotSet()
477456 [ Fact ]
478457 public void AddAzureADBearer_SkipsOptionsValidationForNonAzureCookies ( )
479458 {
480- var services = new ServiceCollection ( ) ;
481- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
482- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
459+ var services = GenerateServicesForTest ( ) ;
483460
484461 services . AddAuthentication ( )
485462 . AddAzureADBearer ( o => { } )
@@ -494,8 +471,7 @@ public void AddAzureADBearer_SkipsOptionsValidationForNonAzureCookies()
494471 [ Fact ]
495472 public void AddAzureAD_SkipsOptionsValidationForNonAzureOpenIdConnect ( )
496473 {
497- var services = new ServiceCollection ( ) ;
498- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
474+ var services = GenerateServicesForTest ( ) ;
499475
500476 services . AddAuthentication ( )
501477 . AddAzureAD ( o => { } )
@@ -510,4 +486,12 @@ public void AddAzureAD_SkipsOptionsValidationForNonAzureOpenIdConnect()
510486
511487 Assert . NotNull ( openIdConnectOptions . Get ( "other" ) ) ;
512488 }
489+
490+ private IServiceCollection GenerateServicesForTest ( )
491+ {
492+ var services = new ServiceCollection ( ) ;
493+ services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
494+ services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
495+ return services ;
496+ }
513497}
0 commit comments