2
2
using Azure . Data . Tables ;
3
3
using Azure . Security . KeyVault . Secrets ;
4
4
5
+ using AzureOpenAIProxy . ApiApp . Configurations ;
5
6
using AzureOpenAIProxy . ApiApp . Extensions ;
6
7
7
8
using FluentAssertions ;
@@ -363,4 +364,127 @@ public void Given_AppSettings_When_Invoked_AddTableStorageService_Then_It_Should
363
364
result . Should ( ) . NotBeNull ( )
364
365
. And . BeOfType < TableServiceClient > ( ) ;
365
366
}
367
+
368
+ [ Fact ]
369
+ public void Given_Empty_AzureSettings_When_Added_ToServiceCollection_Then_It_Should_Throw_Exception ( )
370
+ {
371
+ // Arrange
372
+ var dict = new Dictionary < string , string > ( )
373
+ {
374
+ { "Azure" , string . Empty }
375
+ } ;
376
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
377
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
378
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
379
+
380
+ var sc = new ServiceCollection ( ) ;
381
+ sc . AddSingleton < IConfiguration > ( config ) ;
382
+
383
+ sc . AddStorageAccountSettings ( ) ;
384
+
385
+ // Act
386
+ Action action = ( ) => sc . BuildServiceProvider ( ) . GetService < StorageAccountSettings > ( ) ;
387
+
388
+ // Assert
389
+ action . Should ( ) . Throw < InvalidOperationException > ( ) ;
390
+ }
391
+
392
+ [ Fact ]
393
+ public void Given_Empty_StorageAccountSettings_When_Added_ToServiceCollection_Then_It_Should_Throw_Exception ( )
394
+ {
395
+ // Arrange
396
+ var dict = new Dictionary < string , string > ( )
397
+ {
398
+ { "Azure:StorageAccount" , string . Empty }
399
+ } ;
400
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
401
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
402
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
403
+
404
+ var sc = new ServiceCollection ( ) ;
405
+ sc . AddSingleton < IConfiguration > ( config ) ;
406
+
407
+ sc . AddStorageAccountSettings ( ) ;
408
+
409
+ // Act
410
+ Action action = ( ) => sc . BuildServiceProvider ( ) . GetService < StorageAccountSettings > ( ) ;
411
+
412
+ // Assert
413
+ action . Should ( ) . Throw < InvalidOperationException > ( ) ;
414
+ }
415
+
416
+ [ Fact ]
417
+ public void Given_Empty_TableStorageSettings_When_Added_ToServiceCollection_Then_It_Should_Throw_Exception ( )
418
+ {
419
+ // Arrange
420
+ var dict = new Dictionary < string , string > ( )
421
+ {
422
+ { "Azure:StorageAccount:TableStorage" , string . Empty }
423
+ } ;
424
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
425
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
426
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
427
+
428
+ var sc = new ServiceCollection ( ) ;
429
+ sc . AddSingleton < IConfiguration > ( config ) ;
430
+
431
+ sc . AddStorageAccountSettings ( ) ;
432
+
433
+ // Act
434
+ Action action = ( ) => sc . BuildServiceProvider ( ) . GetService < StorageAccountSettings > ( ) ;
435
+
436
+ // Assert
437
+ action . Should ( ) . Throw < InvalidOperationException > ( ) ;
438
+ }
439
+
440
+ [ Theory ]
441
+ [ InlineData ( default ( string ) ) ]
442
+ [ InlineData ( "" ) ]
443
+ public void Given_NullOrEmpty_TableName_When_Added_ToServiceColleciton_Then_It_Should_Throw_Exception ( string ? tableName )
444
+ {
445
+ // Arrange
446
+ var dict = new Dictionary < string , string > ( )
447
+ {
448
+ { "Azure:StorageAccount:TableStorage:TableName" , tableName }
449
+ } ;
450
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
451
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
452
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
453
+
454
+ var sc = new ServiceCollection ( ) ;
455
+ sc . AddSingleton < IConfiguration > ( config ) ;
456
+
457
+ sc . AddStorageAccountSettings ( ) ;
458
+
459
+ // Act
460
+ Action action = ( ) => sc . BuildServiceProvider ( ) . GetService < StorageAccountSettings > ( ) ;
461
+
462
+ // Assert
463
+ action . Should ( ) . Throw < InvalidOperationException > ( ) ;
464
+ }
465
+
466
+ [ Theory ]
467
+ [ InlineData ( "table-name" ) ]
468
+ public void Given_Appsettings_When_Added_ToServiceCollection_Then_It_Should_Return_StorageAccountSettings ( string tableName )
469
+ {
470
+ // Arrange
471
+ var dict = new Dictionary < string , string > ( )
472
+ {
473
+ { "Azure:StorageAccount:TableStorage:TableName" , tableName }
474
+ } ;
475
+ #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
476
+ var config = new ConfigurationBuilder ( ) . AddInMemoryCollection ( dict ) . Build ( ) ;
477
+ #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types.
478
+
479
+ var sc = new ServiceCollection ( ) ;
480
+ sc . AddSingleton < IConfiguration > ( config ) ;
481
+
482
+ sc . AddStorageAccountSettings ( ) ;
483
+
484
+ // Act
485
+ var settings = sc . BuildServiceProvider ( ) . GetService < StorageAccountSettings > ( ) ;
486
+
487
+ // Assert
488
+ settings ? . TableStorage . TableName . Should ( ) . BeEquivalentTo ( tableName ) ;
489
+ }
366
490
}
0 commit comments