public static DataContext GetMockDataContext() { var options = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase("fewebsite-test", new InMemoryDatabaseRoot()) .UseLazyLoadingProxies() .EnableSensitiveDataLogging() .Options; var dataContext = new DataContext(options); DBSeeding.SeedUsers(dataContext); _dataContext = dataContext; return(dataContext); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <DataContext>(); context.Database.Migrate(); DBSeeding.SeedUsers(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration."); } } host.Run(); }