/// <summary> /// Application entry. /// </summary> /// <param name="args">Arguments.</param> public static void Main(string[] args) { IWebHost host = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = host.Services.CreateScope()) { try { ProductsWebApiContext context = scope.ServiceProvider.GetService <ProductsWebApiContext>(); if (context.Database.IsSqlServer()) { context.Database.Migrate(); } ProductsWebApiInitializer.Initialize(context); } catch (Exception ex) { ILogger <Program> logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating or initializing the database."); } } host.Run(); }
public void SeedDbContext() { //Arrange ProductsWebApiContext dbContext = DbContextHelper.GetDbContext(); //Act ProductsWebApiInitializer.Initialize(dbContext); // Assert dbContext.Products.Count().Should().BeGreaterThan(0); }
private static IProductFacade GetProductsFacade() { ProductsWebApiContext dbContext = DbContextHelper.GetDbContext(); ProductsWebApiInitializer.Initialize(dbContext); var mappingConfig = new MapperConfiguration(configuration => { configuration.AddProfile <ProductMappingProfile>(); }); return(new ProductFacade(dbContext, mappingConfig.CreateMapper())); }