public static ApplicationDbContext Create() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var operationalStoreOptions = Options.Create( new OperationalStoreOptions { DeviceFlowCodes = new TableConfiguration("DeviceCodes"), PersistedGrants = new TableConfiguration("PersistedGrants") }); var currentUserServiceMock = new Mock <ICurrentUserService>(); currentUserServiceMock.Setup(m => m.UserId) .Returns("00000000-0000-0000-0000-000000000000"); var context = new ApplicationDbContext( options, operationalStoreOptions, currentUserServiceMock.Object); ApplicationDbContextInitialiser.Initialise(context); return(context); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var env = services.GetRequiredService <IWebHostEnvironment>(); if (env.IsDevelopment()) { var context = services.GetRequiredService <ApplicationDbContext>(); ApplicationDbContextInitialiser.Initialise(context); } } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while " + "migrating or initializing the database."); throw; } } host.Run(); }