Esempio n. 1
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 5
0
        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());
            });
        }
Esempio n. 6
0
        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);
                }
        }
Esempio n. 7
0
        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);
                }
        }
Esempio n. 8
0
        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);
                }
        }
Esempio n. 9
0
        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);
                }
        }
Esempio n. 10
0
        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);
                }
        }
Esempio n. 11
0
        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);
                }
        }
Esempio n. 12
0
        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.");
            }
        }
Esempio n. 13
0
        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();
        }
Esempio n. 14
0
 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);
     }
 }
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
        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();
        }
Esempio n. 17
0
        public static void Main(string[] args)
        {
            DbContextInitializer.Initialize();

            CreateWebHostBuilder(args).Build().Run();
        }