From b9aa18a0437956c8647dfb78078c74b4391e7ae2 Mon Sep 17 00:00:00 2001 From: Meysam Hadeli <35596795+meysamhadeli@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:59:40 +0330 Subject: [PATCH] fix: fix issue in seed-manager --- src/BuildingBlocks/EFCore/SeedManagers.cs | 14 +++++++++----- .../IntegrationTest/IdentityTestDataSeeder.cs | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/BuildingBlocks/EFCore/SeedManagers.cs b/src/BuildingBlocks/EFCore/SeedManagers.cs index 6602d4f4..9ba1a3de 100644 --- a/src/BuildingBlocks/EFCore/SeedManagers.cs +++ b/src/BuildingBlocks/EFCore/SeedManagers.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace BuildingBlocks.EFCore; @@ -15,11 +16,14 @@ public async Task ExecuteSeedAsync() await using var scope = serviceProvider.CreateAsyncScope(); var dataSeeders = scope.ServiceProvider.GetServices(); - foreach (var seeder in dataSeeders.Where(x => x is not ITestDataSeeder)) + if (!env.IsEnvironment("test")) { - logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); - await seeder.SeedAllAsync(); - logger.LogInformation("Seed {SeederName} is completed.", seeder.GetType().Name); + 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); + } } } @@ -28,7 +32,7 @@ public async Task ExecuteTestSeedAsync() await using var scope = serviceProvider.CreateAsyncScope(); var dataSeeders = scope.ServiceProvider.GetServices(); - foreach (var seeder in dataSeeders.Where(x => x is not ITestDataSeeder)) + foreach (var seeder in dataSeeders.Where(x => x is ITestDataSeeder)) { logger.LogInformation("Seed {SeederName} is started.", seeder.GetType().Name); await seeder.SeedAllAsync(); diff --git a/src/Services/Identity/tests/IntegrationTest/IdentityTestDataSeeder.cs b/src/Services/Identity/tests/IntegrationTest/IdentityTestDataSeeder.cs index 2d2a7bf2..c7a8ab5b 100644 --- a/src/Services/Identity/tests/IntegrationTest/IdentityTestDataSeeder.cs +++ b/src/Services/Identity/tests/IntegrationTest/IdentityTestDataSeeder.cs @@ -8,12 +8,12 @@ namespace Integration.Test; -public class IdentityDataSeeder( +public class IdentityTestDataSeeder( UserManager userManager, RoleManager roleManager, IEventDispatcher eventDispatcher ) - : IDataSeeder + : ITestDataSeeder { public async Task SeedAllAsync() {