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 <ApplicationDbContext>(); var dpContext = services.GetRequiredService <DataProtectionKeysContext>(); var functionalSvc = services.GetRequiredService <IFunctionalSvc>(); var countrySvc = services.GetRequiredService <ICountrySvc>(); DbContextInitializer.Initialize(dpContext, context, functionalSvc, countrySvc).Wait(); } catch (Exception ex) { Log.Error("An error occured while seeding the database {Error} {StackTrace} {InnerException} {Source}", ex.Message, ex.StackTrace, ex.InnerException, ex.Source); } } host.Run(); }
public void DropAndCreate() { DbContextValidator.Validate(); var initalizer = new DbContextInitializer(); initalizer.InitializeDatabase(_context); }
public async Task <string> Seed() { await DbContextInitializer.Seed(); await SeedUsers(); return("Success"); }
public static void DbContextInit(HttpApplication httpApplication) { DbContextInitializer.Instance().InitializeDbContextOnce(() => DbContextManager.Init( DbContextCategory.MallDBContext.ToString(), new[] { "TMall.DomainModule.DBMapping.dll" }, new[] { "TMall.DomainModule.DBMapping.MainDB" }, false, true)); DbContextManager.InitStorage(new WebDbContextStorage(httpApplication)); }
protected void Application_BeginRequest(object sender, EventArgs e) { //Database.SetInitializer(new FlyingClub.Data.Model.NtxfcDbContextInitializer()); DbContextInitializer.Instance().InitializeObjectContextOnce(() => { DbContextManager.InitStorage(_objectContextStorage); //ObjectContextManager.Init("ntxfc_main", new[] { Server.MapPath("~/bin/FlyingClub.Data.Model.dll") }); DbContextManager.Init(new[] { Server.MapPath("~/bin/FlyingClub.Data.Model.dll") }); System.Diagnostics.Trace.WriteLine("BeginRequest: " + DbContextManager.Current.GetHashCode()); }); }
public void AllEvents_CheckResultIsView() { // Arrange using (var context = DbContextInitializer.GetContext()) using (var eventController = new EventController(context, null, _logger, null)) { // Act var vr = eventController.AllEvents(); // Assert Assert.IsType <ViewResult>(vr.Result); } }
public void CreateEvent_CheckIfModelHasError() { // Arrange using (var context = DbContextInitializer.GetContext()) using (var controller = new EventController(context, null, _logger, null)) { // Act controller.ModelState.AddModelError("error", "some error"); var br = controller.CreateEvent(new CreateEventViewModel()).Result; // Assert Assert.IsType <BadRequestResult>(br); } }
public void AllEvents_CheckIsModelCountResult() { // Arrange using (var context = DbContextInitializer.GetContext()) using (var eventController = new EventController(context, null, _logger, null)) { // Act var vr = ((eventController.AllEvents()).Result as ViewResult); var model = vr.Model as ICollection <AllEventViewModel>; // Assert Assert.Equal <int>(2, model.Count); } }
public void AllEvents_CheckIsTypeModelResult() { // Arrange using (var context = DbContextInitializer.GetContext()) using (var eventController = new EventController(context, null, _logger, null)) { // Act var vr = ((eventController.AllEvents()).Result as ViewResult); var model = vr.Model; // Assert Assert.IsAssignableFrom <IEnumerable <AllEventViewModel> >(model); } }
public void AllEvents_CheckModelResultNotNull() { // Arrange using (var context = DbContextInitializer.GetContext()) using (var eventController = new EventController(context, null, _logger, null)) { // Act var vr = ((eventController.AllEvents()).Result as ViewResult); var model = vr.Model; // Assert Assert.NotNull(model); } }
public void AllEvents_CheckIfModelIsEmpty() { // Arrange using (var context = DbContextInitializer.GetContext(false)) using (var controller = new EventController(context, null, _logger, null)) { // Act var vr = controller.AllEvents().Result as ViewResult; var model = vr.Model as ICollection <AllEventViewModel>; // Assert Assert.IsType <ViewResult>(vr); Assert.Equal <int>(0, model.Count); } }
public static void PrepareDatabase(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; try { var context = services.GetRequiredService <AppDataContext>(); DbContextInitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } }
public static void Main(string[] args) { var env = new HostingEnvironment { ContentRootPath = Directory.GetCurrentDirectory() }; Log.Logger = new LoggerConfiguration() .MinimumLevel.Error() .MinimumLevel.Override("Microsoft", LogEventLevel.Error) .Enrich.FromLogContext() .Enrich.WithProperty("Application", "CMS_APP") .Enrich.WithProperty("MachineName", Environment.MachineName) .Enrich.WithProperty("CurrentManagedThreadId", Environment.CurrentManagedThreadId) .Enrich.WithProperty("OSVersion", Environment.OSVersion) .Enrich.WithProperty("Version", Environment.Version) .Enrich.WithProperty("UserName", Environment.UserName) .Enrich.WithProperty("ProcessId", Process.GetCurrentProcess().Id) .Enrich.WithProperty("ProcessName", Process.GetCurrentProcess().ProcessName) .WriteTo.File(formatter: new CompactJsonFormatter(), path: Path.Combine(env.ContentRootPath + $"{Path.DirectorySeparatorChar}Logs{Path.DirectorySeparatorChar}", $"load_error_{DateTime.Now:yyyyMMdd}.json")) .CreateLogger(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var logger = Log.Logger; var context = services.GetRequiredService <ApplicationDbContext>(); var quartzDbContext = services.GetRequiredService <QuartzDbContext>(); var functional = services.GetRequiredService <IFunctionalService>(); DbContextInitializer.Initialize(context, quartzDbContext, functional, logger).Wait(); } catch (Exception ex) { Log.Error(ex, "An error occurred while seeding the database."); } } host.Run(); }
public void CreateEvent_CheckIfNoUser() { try { // Arrange using (var context = DbContextInitializer.GetContext()) using (var controller = new EventController(context, null, _logger, null)) { // Act Assert.Throws <AggregateException>(() => controller.CreateEvent(new CreateEventViewModel()).Result); } } catch (AggregateException exception) { // Assert Assert.Equal("Unable to load current user ClaimTypes.NameIdentifier", exception.Message); } }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <GameItemsContext>(); DbContextInitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); var dpContext = services.GetRequiredService <DataProtectionKeyContext>(); var functionSvc = services.GetRequiredService <IFunctionalSvc>(); //var countrySvc = services.GetRequiredService<ICountrySvc>(); await DbContextInitializer.InitializeDb(dpContext, context, functionSvc); } catch (Exception ex) { throw new Exception("An error occurred while seeding the database"); } } host.Run(); }
public static void Main(string[] args) { DbContextInitializer.Initialize(); CreateWebHostBuilder(args).Build().Run(); }