-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix db-update exception in tests
- Loading branch information
1 parent
bd345ae
commit cc8989a
Showing
5 changed files
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BuildingBlocks.EFCore; | ||
|
||
public class SeedManager( | ||
IServiceProvider serviceProvider | ||
) | ||
: ISeedManager | ||
ILogger<SeedManager> logger, | ||
IWebHostEnvironment env, | ||
IServiceProvider serviceProvider | ||
) : ISeedManager | ||
{ | ||
public async Task ExecuteAsync() | ||
public async Task ExecuteSeedAsync() | ||
{ | ||
await using var scope = serviceProvider.CreateAsyncScope(); | ||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<SeedManager>>(); | ||
var env = scope.ServiceProvider.GetRequiredService<IWebHostEnvironment>(); | ||
var dataSeeders = scope.ServiceProvider.GetServices<IDataSeeder>(); | ||
|
||
if (env.IsEnvironment("test")) | ||
foreach (var seeder in dataSeeders.Where(x => x is not ITestDataSeeder)) | ||
{ | ||
foreach (var seeder in dataSeeders.Where(x => x is ITestDataSeeder)) | ||
{ | ||
logger.LogInformation("Test Seed {SeederName} is started.", seeder.GetType().Name); | ||
await seeder.SeedAllAsync(); | ||
logger.LogInformation("Test Seed {SeederName} is completed.", seeder.GetType().Name); | ||
} | ||
logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); | ||
await seeder.SeedAllAsync(); | ||
logger.LogInformation("Seed {SeederName} is completed.", seeder.GetType().Name); | ||
} | ||
else | ||
} | ||
|
||
public async Task ExecuteTestSeedAsync() | ||
{ | ||
await using var scope = serviceProvider.CreateAsyncScope(); | ||
var dataSeeders = scope.ServiceProvider.GetServices<IDataSeeder>(); | ||
|
||
foreach (var seeder in dataSeeders.Where(x => x is not ITestDataSeeder)) | ||
{ | ||
foreach (var seeder in dataSeeders.Where(x => x is not ITestDataSeeder)) | ||
{ | ||
logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); | ||
await seeder.SeedAllAsync(); | ||
logger.LogInformation("Seed {SeederName} is completed.", seeder.GetType().Name); | ||
} | ||
logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); | ||
await seeder.SeedAllAsync(); | ||
logger.LogInformation("Seed {SeederName} is completed.", seeder.GetType().Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters