@@ -323,5 +323,305 @@ public void MSSqlServerCallsSinkFactoryWithSuppliedParameters()
323
323
formatProviderMock . Object , autoCreateSqlTable , columnOptions , schemaName , logEventFormatterMock . Object ) ,
324
324
Times . Once ) ;
325
325
}
326
+
327
+ [ Fact ]
328
+ public void MSSqlServerAuditCallsApplyMicrosoftExtensionsConfigurationGetConnectionString ( )
329
+ {
330
+ // Arrange
331
+ const string inputConnectionString = "TestConnectionString" ;
332
+ var appConfigurationMock = new Mock < IConfiguration > ( ) ;
333
+ var columnOptionsSectionMock = new Mock < IConfigurationSection > ( ) ;
334
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
335
+
336
+ // Act
337
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
338
+ connectionString : inputConnectionString ,
339
+ tableName : "TestTableName" ,
340
+ appConfiguration : appConfigurationMock . Object ,
341
+ columnOptionsSection : columnOptionsSectionMock . Object ,
342
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
343
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
344
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
345
+
346
+ // Assert
347
+ _applyMicrosoftExtensionsConfigurationMock . Verify ( c => c . GetConnectionString ( inputConnectionString , appConfigurationMock . Object ) ,
348
+ Times . Once ) ;
349
+ }
350
+
351
+ [ Fact ]
352
+ public void MSSqlServerAuditCallsSinkFactoryWithConnectionStringFromMicrosoftConfigExtensions ( )
353
+ {
354
+ // Arrange
355
+ const string configConnectionString = "TestConnectionStringFromConfig" ;
356
+ _applyMicrosoftExtensionsConfigurationMock . Setup ( c => c . GetConnectionString ( It . IsAny < string > ( ) , It . IsAny < IConfiguration > ( ) ) )
357
+ . Returns ( configConnectionString ) ;
358
+ var appConfigurationMock = new Mock < IConfiguration > ( ) ;
359
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
360
+
361
+ // Act
362
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
363
+ connectionString : "TestConnectionString" ,
364
+ tableName : "TestTableName" ,
365
+ appConfiguration : appConfigurationMock . Object ,
366
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
367
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
368
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
369
+
370
+ // Assert
371
+ auditSinkFactoryMock . Verify ( f => f . Create ( configConnectionString , It . IsAny < string > ( ) , It . IsAny < IFormatProvider > ( ) ,
372
+ It . IsAny < bool > ( ) , It . IsAny < ColumnOptions > ( ) , It . IsAny < string > ( ) , It . IsAny < ITextFormatter > ( ) ) , Times . Once ) ;
373
+ }
374
+
375
+ [ Fact ]
376
+ public void MSSqlServerAuditDoesNotCallApplyMicrosoftExtensionsConfigurationGetConnectionStringWhenAppConfigIsNull ( )
377
+ {
378
+ // Arrange
379
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
380
+
381
+ // Act
382
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
383
+ connectionString : "TestConnectionString" ,
384
+ tableName : "TestTableName" ,
385
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
386
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
387
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
388
+
389
+ // Assert
390
+ _applyMicrosoftExtensionsConfigurationMock . Verify ( c => c . GetConnectionString ( It . IsAny < string > ( ) , It . IsAny < IConfiguration > ( ) ) ,
391
+ Times . Never ) ;
392
+ }
393
+
394
+ [ Fact ]
395
+ public void MSSqlServerAuditCallsApplyMicrosoftExtensionsConfigurationGetColumnOptions ( )
396
+ {
397
+ // Arrange
398
+ var columnOptions = new ColumnOptions ( ) ;
399
+ var columnOptionsSectionMock = new Mock < IConfigurationSection > ( ) ;
400
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
401
+
402
+ // Act
403
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
404
+ connectionString : "TestConnectionString" ,
405
+ tableName : "TestTableName" ,
406
+ columnOptions : columnOptions ,
407
+ columnOptionsSection : columnOptionsSectionMock . Object ,
408
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
409
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
410
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
411
+
412
+ // Assert
413
+ _applyMicrosoftExtensionsConfigurationMock . Verify ( c => c . ConfigureColumnOptions ( columnOptions , columnOptionsSectionMock . Object ) ,
414
+ Times . Once ) ;
415
+ }
416
+
417
+ [ Fact ]
418
+ public void MSSqlServerAuditCallsSinkFactoryWithColumnOptionsFromMicrosoftConfigExtensions ( )
419
+ {
420
+ // Arrange
421
+ var configColumnOptions = new ColumnOptions ( ) ;
422
+ var columnOptionsSectionMock = new Mock < IConfigurationSection > ( ) ;
423
+ _applyMicrosoftExtensionsConfigurationMock . Setup ( c => c . ConfigureColumnOptions ( It . IsAny < ColumnOptions > ( ) , It . IsAny < IConfigurationSection > ( ) ) )
424
+ . Returns ( configColumnOptions ) ;
425
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
426
+
427
+ // Act
428
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
429
+ connectionString : "TestConnectionString" ,
430
+ tableName : "TestTableName" ,
431
+ columnOptions : new ColumnOptions ( ) ,
432
+ columnOptionsSection : columnOptionsSectionMock . Object ,
433
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
434
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
435
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
436
+
437
+ // Assert
438
+ auditSinkFactoryMock . Verify ( f => f . Create ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < IFormatProvider > ( ) ,
439
+ It . IsAny < bool > ( ) , configColumnOptions , It . IsAny < string > ( ) , It . IsAny < ITextFormatter > ( ) ) , Times . Once ) ;
440
+ }
441
+
442
+ [ Fact ]
443
+ public void MSSqlServerAuditDoesNotCallApplyMicrosoftExtensionsConfigurationGetColumnOptionsWhenConfigSectionIsNull ( )
444
+ {
445
+ // Arrange
446
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
447
+
448
+ // Act
449
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
450
+ connectionString : "TestConnectionString" ,
451
+ tableName : "TestTableName" ,
452
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
453
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
454
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
455
+
456
+ // Assert
457
+ _applyMicrosoftExtensionsConfigurationMock . Verify ( c => c . ConfigureColumnOptions ( It . IsAny < ColumnOptions > ( ) , It . IsAny < IConfigurationSection > ( ) ) ,
458
+ Times . Never ) ;
459
+ }
460
+
461
+ [ Fact ]
462
+ public void MSSqlServerAuditCallsApplySystemConfigurationGetConnectionString ( )
463
+ {
464
+ // Arrange
465
+ const string inputConnectionString = "TestConnectionString" ;
466
+ _applySystemConfigurationMock . Setup ( c => c . GetSinkConfigurationSection ( It . IsAny < string > ( ) ) )
467
+ . Returns ( new MSSqlServerConfigurationSection ( ) ) ;
468
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
469
+
470
+ // Act
471
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
472
+ connectionString : inputConnectionString ,
473
+ tableName : "TestTableName" ,
474
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
475
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
476
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
477
+
478
+ // Assert
479
+ _applySystemConfigurationMock . Verify ( c => c . GetConnectionString ( inputConnectionString ) ,
480
+ Times . Once ) ;
481
+ }
482
+
483
+ [ Fact ]
484
+ public void MSSqlServerAuditCallsSinkFactoryWithConnectionStringFromSystemConfig ( )
485
+ {
486
+ // Arrange
487
+ const string configConnectionString = "TestConnectionStringFromConfig" ;
488
+ _applySystemConfigurationMock . Setup ( c => c . GetSinkConfigurationSection ( It . IsAny < string > ( ) ) )
489
+ . Returns ( new MSSqlServerConfigurationSection ( ) ) ;
490
+ _applySystemConfigurationMock . Setup ( c => c . GetConnectionString ( It . IsAny < string > ( ) ) )
491
+ . Returns ( configConnectionString ) ;
492
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
493
+
494
+ // Act
495
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
496
+ connectionString : "TestConnectionString" ,
497
+ tableName : "TestTableName" ,
498
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
499
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
500
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
501
+
502
+ // Assert
503
+ auditSinkFactoryMock . Verify ( f => f . Create ( configConnectionString , It . IsAny < string > ( ) , It . IsAny < IFormatProvider > ( ) ,
504
+ It . IsAny < bool > ( ) , It . IsAny < ColumnOptions > ( ) , It . IsAny < string > ( ) , It . IsAny < ITextFormatter > ( ) ) , Times . Once ) ;
505
+ }
506
+
507
+ [ Fact ]
508
+ public void MSSqlServerAuditDoesNotCallApplySystemConfigurationGetConnectionStringWhenNotUsingSystemConfig ( )
509
+ {
510
+ // Arrange
511
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
512
+
513
+ // Act
514
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
515
+ connectionString : "TestConnectionString" ,
516
+ tableName : "TestTableName" ,
517
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
518
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
519
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
520
+
521
+ // Assert
522
+ _applySystemConfigurationMock . Verify ( c => c . GetConnectionString ( It . IsAny < string > ( ) ) , Times . Never ) ;
523
+ }
524
+
525
+ [ Fact ]
526
+ public void MSSqlServerAuditCallsApplySystemConfigurationGetColumnOptions ( )
527
+ {
528
+ // Arrange
529
+ var columnOptions = new ColumnOptions ( ) ;
530
+ var systemConfigSection = new MSSqlServerConfigurationSection ( ) ;
531
+ _applySystemConfigurationMock . Setup ( c => c . GetSinkConfigurationSection ( It . IsAny < string > ( ) ) )
532
+ . Returns ( systemConfigSection ) ;
533
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
534
+
535
+ // Act
536
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
537
+ connectionString : "TestConnectionString" ,
538
+ tableName : "TestTableName" ,
539
+ columnOptions : columnOptions ,
540
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
541
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
542
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
543
+
544
+ // Assert
545
+ _applySystemConfigurationMock . Verify ( c => c . ConfigureColumnOptions ( systemConfigSection , columnOptions ) ,
546
+ Times . Once ) ;
547
+ }
548
+
549
+ [ Fact ]
550
+ public void MSSqlServerAuditCallsSinkFactoryWithColumnOptionsFromSystemConfig ( )
551
+ {
552
+ // Arrange
553
+ var configColumnOptions = new ColumnOptions ( ) ;
554
+ _applySystemConfigurationMock . Setup ( c => c . GetSinkConfigurationSection ( It . IsAny < string > ( ) ) )
555
+ . Returns ( new MSSqlServerConfigurationSection ( ) ) ;
556
+ _applySystemConfigurationMock . Setup ( c => c . ConfigureColumnOptions ( It . IsAny < MSSqlServerConfigurationSection > ( ) , It . IsAny < ColumnOptions > ( ) ) )
557
+ . Returns ( configColumnOptions ) ;
558
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
559
+
560
+ // Act
561
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
562
+ connectionString : "TestConnectionString" ,
563
+ tableName : "TestTableName" ,
564
+ columnOptions : new ColumnOptions ( ) ,
565
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
566
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
567
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
568
+
569
+ // Assert
570
+ auditSinkFactoryMock . Verify ( f => f . Create ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < IFormatProvider > ( ) ,
571
+ It . IsAny < bool > ( ) , configColumnOptions , It . IsAny < string > ( ) , It . IsAny < ITextFormatter > ( ) ) , Times . Once ) ;
572
+ }
573
+
574
+ [ Fact ]
575
+ public void MSSqlServerAuditDoesNotCallApplySystemConfigurationGetColumnOptionsWhenNotUsingSystemConfig ( )
576
+ {
577
+ // Arrange
578
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
579
+
580
+ // Act
581
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
582
+ connectionString : "TestConnectionString" ,
583
+ tableName : "TestTableName" ,
584
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
585
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
586
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
587
+
588
+ // Assert
589
+ _applySystemConfigurationMock . Verify ( c => c . ConfigureColumnOptions ( It . IsAny < MSSqlServerConfigurationSection > ( ) , It . IsAny < ColumnOptions > ( ) ) ,
590
+ Times . Never ) ;
591
+ }
592
+
593
+ [ Fact ]
594
+ public void MSSqlServerAuditCallsSinkFactoryWithSuppliedParameters ( )
595
+ {
596
+ // Arrange
597
+ const string connectionString = "TestConnectionString" ;
598
+ const string tableName = "TestTableName" ;
599
+ const bool autoCreateSqlTable = true ;
600
+ const string schemaName = "TestSchemaName" ;
601
+ var columnOptions = new ColumnOptions ( ) ;
602
+ var batchPeriod = new TimeSpan ( 0 , 0 , 44 ) ;
603
+ var formatProviderMock = new Mock < IFormatProvider > ( ) ;
604
+ var logEventFormatterMock = new Mock < ITextFormatter > ( ) ;
605
+
606
+ var auditSinkFactoryMock = new Mock < IMSSqlServerAuditSinkFactory > ( ) ;
607
+
608
+ // Act
609
+ _loggerConfiguration . AuditTo . MSSqlServerInternal (
610
+ connectionString : connectionString ,
611
+ tableName : tableName ,
612
+ columnOptions : columnOptions ,
613
+ formatProvider : formatProviderMock . Object ,
614
+ autoCreateSqlTable : autoCreateSqlTable ,
615
+ schemaName : schemaName ,
616
+ logEventFormatter : logEventFormatterMock . Object ,
617
+ applySystemConfiguration : _applySystemConfigurationMock . Object ,
618
+ applyMicrosoftExtensionsConfiguration : _applyMicrosoftExtensionsConfigurationMock . Object ,
619
+ auditSinkFactory : auditSinkFactoryMock . Object ) ;
620
+
621
+ // Assert
622
+ auditSinkFactoryMock . Verify ( f => f . Create ( connectionString , tableName ,
623
+ formatProviderMock . Object , autoCreateSqlTable , columnOptions , schemaName , logEventFormatterMock . Object ) ,
624
+ Times . Once ) ;
625
+ }
326
626
}
327
627
}
0 commit comments