@@ -20,9 +20,7 @@ public class AzureADAuthenticationBuilderExtensionsTests
20
20
public void AddAzureAD_AddsAllAuthenticationHandlers ( )
21
21
{
22
22
// Arrange
23
- var services = new ServiceCollection ( ) ;
24
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
25
- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
23
+ var services = GenerateServicesForTest ( ) ;
26
24
27
25
// Act
28
26
services . AddAuthentication ( )
@@ -39,8 +37,7 @@ public void AddAzureAD_AddsAllAuthenticationHandlers()
39
37
public void AddAzureAD_ConfiguresAllOptions ( )
40
38
{
41
39
// Arrange
42
- var services = new ServiceCollection ( ) ;
43
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
40
+ var services = GenerateServicesForTest ( ) ;
44
41
45
42
// Act
46
43
services . AddAuthentication ( )
@@ -89,8 +86,7 @@ public void AddAzureAD_ConfiguresAllOptions()
89
86
public void AddAzureAD_AllowsOverridingCookiesAndOpenIdConnectSettings ( )
90
87
{
91
88
// Arrange
92
- var services = new ServiceCollection ( ) ;
93
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
89
+ var services = GenerateServicesForTest ( ) ;
94
90
95
91
// Act
96
92
services . AddAuthentication ( )
@@ -134,8 +130,7 @@ public void AddAzureAD_AllowsOverridingCookiesAndOpenIdConnectSettings()
134
130
public void AddAzureAD_RegisteringAddCookiesAndAddOpenIdConnectHasNoImpactOnAzureAAExtensions ( )
135
131
{
136
132
// Arrange
137
- var services = new ServiceCollection ( ) ;
138
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
133
+ var services = GenerateServicesForTest ( ) ;
139
134
140
135
// Act
141
136
services . AddAuthentication ( )
@@ -181,8 +176,7 @@ public void AddAzureAD_RegisteringAddCookiesAndAddOpenIdConnectHasNoImpactOnAzur
181
176
public void AddAzureAD_ThrowsForDuplicatedSchemes ( )
182
177
{
183
178
// Arrange
184
- var services = new ServiceCollection ( ) ;
185
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
179
+ var services = GenerateServicesForTest ( ) ;
186
180
187
181
services . AddAuthentication ( )
188
182
. AddAzureAD ( o => { } )
@@ -202,8 +196,7 @@ public void AddAzureAD_ThrowsForDuplicatedSchemes()
202
196
public void AddAzureAD_ThrowsWhenOpenIdSchemeIsAlreadyInUse ( )
203
197
{
204
198
// Arrange
205
- var services = new ServiceCollection ( ) ;
206
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
199
+ var services = GenerateServicesForTest ( ) ;
207
200
208
201
services . AddAuthentication ( )
209
202
. AddAzureAD ( o => { } )
@@ -226,8 +219,7 @@ public void AddAzureAD_ThrowsWhenOpenIdSchemeIsAlreadyInUse()
226
219
public void AddAzureAD_ThrowsWhenCookieSchemeIsAlreadyInUse ( )
227
220
{
228
221
// Arrange
229
- var services = new ServiceCollection ( ) ;
230
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
222
+ var services = GenerateServicesForTest ( ) ;
231
223
232
224
services . AddAuthentication ( )
233
225
. AddAzureAD ( o => { } )
@@ -250,8 +242,7 @@ public void AddAzureAD_ThrowsWhenCookieSchemeIsAlreadyInUse()
250
242
public void AddAzureAD_ThrowsWhenInstanceIsNotSet ( )
251
243
{
252
244
// Arrange
253
- var services = new ServiceCollection ( ) ;
254
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
245
+ var services = GenerateServicesForTest ( ) ;
255
246
256
247
services . AddAuthentication ( )
257
248
. AddAzureAD ( o => { } ) ;
@@ -271,8 +262,7 @@ public void AddAzureAD_ThrowsWhenInstanceIsNotSet()
271
262
[ Fact ]
272
263
public void AddAzureAD_SkipsOptionsValidationForNonAzureCookies ( )
273
264
{
274
- var services = new ServiceCollection ( ) ;
275
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
265
+ var services = GenerateServicesForTest ( ) ;
276
266
277
267
services . AddAuthentication ( )
278
268
. AddAzureAD ( o => { } )
@@ -288,9 +278,7 @@ public void AddAzureAD_SkipsOptionsValidationForNonAzureCookies()
288
278
public void AddAzureADBearer_AddsAllAuthenticationHandlers ( )
289
279
{
290
280
// Arrange
291
- var services = new ServiceCollection ( ) ;
292
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
293
- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
281
+ var services = GenerateServicesForTest ( ) ;
294
282
295
283
// Act
296
284
services . AddAuthentication ( )
@@ -306,9 +294,7 @@ public void AddAzureADBearer_AddsAllAuthenticationHandlers()
306
294
public void AddAzureADBearer_ConfiguresAllOptions ( )
307
295
{
308
296
// Arrange
309
- var services = new ServiceCollection ( ) ;
310
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
311
- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
297
+ var services = GenerateServicesForTest ( ) ;
312
298
313
299
// Act
314
300
services . AddAuthentication ( )
@@ -342,9 +328,7 @@ public void AddAzureADBearer_ConfiguresAllOptions()
342
328
public void AddAzureADBearer_CanOverrideJwtBearerOptionsConfiguration ( )
343
329
{
344
330
// Arrange
345
- var services = new ServiceCollection ( ) ;
346
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
347
- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
331
+ var services = GenerateServicesForTest ( ) ;
348
332
349
333
// Act
350
334
services . AddAuthentication ( )
@@ -376,9 +360,7 @@ public void AddAzureADBearer_CanOverrideJwtBearerOptionsConfiguration()
376
360
public void AddAzureADBearer_RegisteringJwtBearerHasNoImpactOnAzureAAExtensions ( )
377
361
{
378
362
// Arrange
379
- var services = new ServiceCollection ( ) ;
380
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
381
- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
363
+ var services = GenerateServicesForTest ( ) ;
382
364
383
365
// Act
384
366
services . AddAuthentication ( )
@@ -411,8 +393,7 @@ public void AddAzureADBearer_RegisteringJwtBearerHasNoImpactOnAzureAAExtensions(
411
393
public void AddAzureADBearer_ThrowsForDuplicatedSchemes ( )
412
394
{
413
395
// Arrange
414
- var services = new ServiceCollection ( ) ;
415
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
396
+ var services = GenerateServicesForTest ( ) ;
416
397
417
398
services . AddAuthentication ( )
418
399
. AddAzureADBearer ( o => { } )
@@ -432,8 +413,7 @@ public void AddAzureADBearer_ThrowsForDuplicatedSchemes()
432
413
public void AddAzureADBearer_ThrowsWhenBearerSchemeIsAlreadyInUse ( )
433
414
{
434
415
// Arrange
435
- var services = new ServiceCollection ( ) ;
436
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
416
+ var services = GenerateServicesForTest ( ) ;
437
417
438
418
services . AddAuthentication ( )
439
419
. AddAzureADBearer ( o => { } )
@@ -456,8 +436,7 @@ public void AddAzureADBearer_ThrowsWhenBearerSchemeIsAlreadyInUse()
456
436
public void AddAzureADBearer_ThrowsWhenInstanceIsNotSet ( )
457
437
{
458
438
// Arrange
459
- var services = new ServiceCollection ( ) ;
460
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
439
+ var services = GenerateServicesForTest ( ) ;
461
440
462
441
services . AddAuthentication ( )
463
442
. AddAzureADBearer ( o => { } ) ;
@@ -477,9 +456,7 @@ public void AddAzureADBearer_ThrowsWhenInstanceIsNotSet()
477
456
[ Fact ]
478
457
public void AddAzureADBearer_SkipsOptionsValidationForNonAzureCookies ( )
479
458
{
480
- var services = new ServiceCollection ( ) ;
481
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
482
- services . AddSingleton < IConfiguration > ( new ConfigurationManager ( ) ) ;
459
+ var services = GenerateServicesForTest ( ) ;
483
460
484
461
services . AddAuthentication ( )
485
462
. AddAzureADBearer ( o => { } )
@@ -494,8 +471,7 @@ public void AddAzureADBearer_SkipsOptionsValidationForNonAzureCookies()
494
471
[ Fact ]
495
472
public void AddAzureAD_SkipsOptionsValidationForNonAzureOpenIdConnect ( )
496
473
{
497
- var services = new ServiceCollection ( ) ;
498
- services . AddSingleton < ILoggerFactory > ( new NullLoggerFactory ( ) ) ;
474
+ var services = GenerateServicesForTest ( ) ;
499
475
500
476
services . AddAuthentication ( )
501
477
. AddAzureAD ( o => { } )
@@ -510,4 +486,12 @@ public void AddAzureAD_SkipsOptionsValidationForNonAzureOpenIdConnect()
510
486
511
487
Assert . NotNull ( openIdConnectOptions . Get ( "other" ) ) ;
512
488
}
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
+ }
513
497
}
0 commit comments