@@ -11,64 +11,48 @@ namespace Tests.CodeOfChaos.Types.DataSeeder;
1111// ---------------------------------------------------------------------------------------------------------------------
1212public class SeederTests {
1313 [ Test ]
14- public async Task StartAsync_ShouldLogAndReturn_WhenShouldSeedReturnsFalse ( ) {
15- // Arrange
16- var loggerMock = new Mock < ILogger > ( ) ;
17- var seeder = new TestSeeder {
18- ShouldSeedResult = false // Simulate ShouldSeedAsync returning false
19- } ;
14+ public async Task StartAsync_ShouldLogAndReturn_WhenShouldSeedReturnsFalse ( ) {
15+ // Arrange
16+ var serviceProviderMock = new Mock < IServiceProvider > ( ) ;
17+ var seeder = new TestSeeder {
18+ ShouldSeedResult = false // Simulate ShouldSeedAsync returning false
19+ } ;
2020
21- // Act
22- await seeder . StartAsync ( loggerMock . Object ) ;
21+ // Act
22+ await seeder . StartAsync ( serviceProviderMock . Object ) ;
2323
24- // Assert
25- loggerMock . Verify (
26- expression : logger => logger . Log (
27- LogLevel . Information ,
28- It . IsAny < EventId > ( ) ,
29- It . Is < It . IsAnyType > ( ( state , _ ) => state . ToString ( ) ! . Contains ( "Skipping seeding" ) ) ,
30- It . IsAny < Exception > ( ) ,
31- It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ! ) ,
32- Times . Once ) ;
33- await Assert . That ( seeder . SeedWasCalled ) . IsFalse ( ) ;
34- }
24+ // Assert
25+ await Assert . That ( seeder . ShouldSeed ) . IsFalse ( ) ;
26+ }
3527
3628 [ Test ]
37- public async Task StartAsync_ShouldCallSeed_WhenShouldSeedReturnsTrue ( ) {
38- // Arrange
39- var loggerMock = new Mock < ILogger > ( ) ;
40- var seeder = new TestSeeder {
41- ShouldSeedResult = true // Simulate ShouldSeedAsync returning true
42- } ;
29+ public async Task StartAsync_ShouldCallSeed_WhenShouldSeedReturnsTrue ( ) {
30+ // Arrange
31+ var serviceProviderMock = new Mock < IServiceProvider > ( ) ;
32+ var seeder = new TestSeeder {
33+ ShouldSeedResult = true // Simulate ShouldSeedAsync returning true
34+ } ;
4335
44- // Act
45- await seeder . StartAsync ( loggerMock . Object ) ;
36+ // Act
37+ await seeder . StartAsync ( serviceProviderMock . Object ) ;
4638
47- // Assert
48- loggerMock . Verify (
49- expression : logger => logger . Log (
50- It . IsAny < LogLevel > ( ) ,
51- It . IsAny < EventId > ( ) ,
52- It . IsAny < It . IsAnyType > ( ) ,
53- It . IsAny < Exception > ( ) ,
54- It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ! ) ,
55- Times . Never ) ; // No additional logging should occur during SeedAsync
56- await Assert . That ( seeder . SeedWasCalled ) . IsTrue ( ) ;
57- }
39+ // Assert
40+ await Assert . That ( seeder . ShouldSeed ) . IsTrue ( ) ;
41+ }
5842
5943 [ Test ]
60- public async Task StartAsync_ShouldRespectCancellationToken ( ) {
61- // Arrange
62- var loggerMock = new Mock < ILogger > ( ) ;
63- var seeder = new TestSeeder ( ) ;
64- using var cts = new CancellationTokenSource ( ) ;
65- await cts . CancelAsync ( ) ; // Simulate cancellation
44+ public async Task StartAsync_ShouldRespectCancellationToken ( ) {
45+ // Arrange
46+ var serviceProviderMock = new Mock < IServiceProvider > ( ) ;
47+ var seeder = new TestSeeder ( ) ;
48+ using var cts = new CancellationTokenSource ( ) ;
49+ await cts . CancelAsync ( ) ; // Simulate cancellation
6650
67- // Act & Assert
68- await Assert . ThrowsAsync < OperationCanceledException > ( async ( ) => {
69- await seeder . StartAsync ( loggerMock . Object , cts . Token ) ;
70- } ) ;
71- }
51+ // Act & Assert
52+ await Assert . ThrowsAsync < OperationCanceledException > ( async ( ) => {
53+ await seeder . StartAsync ( serviceProviderMock . Object , cts . Token ) ;
54+ } ) ;
55+ }
7256
7357 // Test implementation of Seeder for unit tests
7458 public class TestSeeder : Seeder {
0 commit comments