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()) { try { DBSeeding.SeedDatabase(scope.ServiceProvider); } catch (Exception e) { Console.WriteLine(e.Message); throw; } } host.Run(); }
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(); }