public async static Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var netCoreAppContext = services.GetRequiredService <NetCoreAppContext>(); await NetCoreAppContextSeed.SeedAsync(netCoreAppContext); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await AppIdentityDbContextSeed.SeedAsync(userManager, roleManager); } catch (Exception ex) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public async Task Test_MaxId_et_CountAsync_Retourne_Le_Maximum() { await NetCoreAppContextSeed.SeedAsync(_dbContext); int maxId = _categorieRepository.MaxId(); Assert.Equal(10, maxId); Categorie categorie = new Categorie(11, "Eau"); await _categorieRepository.AddAsync(categorie); maxId = _categorieRepository.MaxId(); Assert.Equal(11, maxId); var rowsCount = await _categorieRepository.CountAsync(); Assert.Equal(11, rowsCount); }
public async Task Test_Methode_SeedAsync() { await NetCoreAppContextSeed.SeedAsync(_dbContext); int count_categorie = await _categorieRepository.CountAsync(); Assert.Equal(10, count_categorie); int count_Articles = await _articleRepository.CountAsync(); Assert.Equal(3, count_Articles); var categorie = await _categorieRepository.GetByIdAsync(5); Assert.Equal("Chaussette", categorie.Libelle); var article = await _articleRepository.GetByIdAsync(2); Assert.Equal("Polo Tommy HilFiger", article.Libelle); Assert.Equal(1, article.CategorieId); Assert.Equal(20, article.Prix); Assert.Equal(75, article.Stock); }
public void Test_GetCategoriesFromJsonFile_Retourne_Liste_Des_Categories() { var categories = NetCoreAppContextSeed.GetCategoriesFromJsonFile(); Assert.Equal(10, categories.ToList().Count); }