public void GetSeedJsonData_Should_Load_UserPrompts_Json()
        {
            var result = SeedDataLoader.GetSeedJsonData <List <UserPrompt> >(Constants.SeedDataFiles.UserPrompts);

            result.ShouldNotBeNull();
            result.Count.ShouldBeGreaterThan(0);
        }
        public void GetSeedJsonData_Should_Load_MiniApps_Json()
        {
            var result = SeedDataLoader.GetSeedJsonData <List <MiniApp> >(Constants.SeedDataFiles.MiniApps);

            result.ShouldNotBeNull();
            result.Count.ShouldBeGreaterThan(0);
        }
        public void GetSeedJsonData_Should_Load_ExternalLinks_Json()
        {
            var result = SeedDataLoader.GetSeedJsonData <List <ExternalLink> >(Constants.SeedDataFiles.ExternalLinks);

            result.ShouldNotBeNull();
            result.Count.ShouldBeGreaterThan(0);
        }
        public void GetSeedJsonData_Should_Load_NutrientIcons_Json()
        {
            var result = SeedDataLoader.GetSeedJsonData <List <NutrientIcon> >(Constants.SeedDataFiles.NutrientIcons);

            result.ShouldNotBeNull();
            result.Count.ShouldBeGreaterThan(0);
        }
        public void GetSeedJsonData_Should_Load_BrowserData_Json()
        {
            var result = SeedDataLoader.GetSeedJsonData <List <Browser> >(Constants.SeedDataFiles.Browsers);

            result.ShouldNotBeNull();
            result.Count.ShouldBeGreaterThan(0);
        }
示例#6
0
        public static void Main(string[] args)
        {
            SeedDataLoader seedDataLoader = new SeedDataLoader();

            seedDataLoader.LoadData();
//            BuildWebHost(args).Run();
        }
        public void GetMigrationSeedData()
        {
            var result = SeedDataLoader.GetMigrationSeedData <List <UserPrompt> >("1_UserPrompts");

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data);
            Assert.IsTrue(result.Data.Count > 0);
            Assert.IsTrue(result.AppliedDateTime > default(DateTime));
        }
示例#8
0
文件: Startup.cs 项目: kant/embc-ess
        private void SetupDatabase(IHostingEnvironment env, EmbcDbContext adminCtx)
        {
            log.LogInformation("Fetching the application's database context ...");

            if (configuration.DbFullRefresh())
            {
                log.LogWarning("DROPPING the database! ...");
                adminCtx.Database.EnsureDeleted();
            }

            log.LogInformation("Initializing the database ...");
            if (configuration.HasDbAdminPassword())
            {
                //For OpenShift deployments
                DatabaseTools.CreateDatabaseIfNotExists(DatabaseTools.GetSaConnectionString(configuration, "master"),
                                                        configuration.GetDbName(),
                                                        configuration.GetDbUser(),
                                                        configuration.GetDbUserPassword());
            }

            log.LogInformation("Syncing migrations prior to migrating...");
            DatabaseTools.SyncInitialMigration(DatabaseTools.GetSaConnectionString(configuration));

            log.LogInformation("Migrating the database ...");
            adminCtx.Database.Migrate();

            log.LogInformation("The database migration is complete.");

            try
            {
                // run the database seeders
                log.LogInformation("Adding/Updating seed data ...");

                ISeederRepository seederRepository = new SeederRepository(adminCtx);
                var seedDataLoader = new SeedDataLoader(loggerFactory);
                var seeder         = new EmbcSeeder(loggerFactory, seederRepository, env, seedDataLoader);
                seeder.SeedData();

                log.LogInformation("Seeding operations are complete.");
            }
            catch (Exception e)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendLine("The database setup failed!");
                msg.AppendLine("The database may not be available and the application will not function as expected.");
                msg.AppendLine("Please ensure a database is available and the connection string is correct.");
                msg.AppendLine("If you are running in a development environment, ensure your test database and server configuration match the project's default connection string.");
                msg.AppendLine("Error message is " + e.Message);
                log.LogCritical(new EventId(-1, "Database Seeding Failed"), e, msg.ToString());
            }
        }
        public void GetSeedJsonData_Should_Load_Journies_Json()
        {
            var result = SeedDataLoader.GetSeedJsonData <List <Journey> >(Constants.SeedDataFiles.Journey);

            result.ShouldNotBeNull();
            result.Count.ShouldBe(6);
            result.SelectMany(j => j.MainMenus).Count().ShouldBe(26);
            result.SelectMany(j => j.MainMenus).SelectMany(m => m.SubMenus).Count().ShouldBe(28);

            result.SingleOrDefault(r => r.Name.Equals("Ranch", StringComparison.OrdinalIgnoreCase)).ShouldNotBeNull();
            result.SingleOrDefault(r => r.Name.Equals("Ranch", StringComparison.OrdinalIgnoreCase))
            .MainMenus.Any(m => !string.IsNullOrWhiteSpace(m.Page) &&
                           m.Page.Equals("RanchAnimals/Index", StringComparison.OrdinalIgnoreCase) &&
                           m.SubMenus.Any(sb => sb.Page.Equals("RanchAnimals/Index", StringComparison.OrdinalIgnoreCase)))
            .ShouldBeTrue();
        }
示例#10
0
 public void Test()
 {
     WithEventRepository((service, repository) =>
     {
         var loader = new SeedDataLoader(Options.Create(options), service, new ChannelMessageHub());
         Path.GetFileName(service.ConnectionString.Filename).Should().Be("_Test.litedb");
         loader.Load(false);
         var events = service.List <EventDto>().ToList();
         events.Should().HaveCount(1);
         var ev = events[0];
         ev.Id.Should().Be(new Guid("08d91d00795fca4b870eae38900278be"));
         ev.Name.Should().Be("Тестовая гонка");
         ev.Created.Should().BeCloseTo(DateTime.UtcNow, 5000);
         ev.Name = "some";
         service.Save(ev);
         loader.Load(false);
         service.List <EventDto>().Single().Name.Should().Be("some");
         loader.Load(true);
         service.List <EventDto>().Single().Name.Should().Be("Тестовая гонка");
     });
 }
示例#11
0
        public SeederTests()
        {
            var loggerFactory = Substitute.For <ILoggerFactory>();

            this.seedDataLoader = new SeedDataLoader(loggerFactory);
        }
示例#12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            var env           = app.ApplicationServices.GetService <IHostingEnvironment>();
            var loggerFactory = app.ApplicationServices.GetService <ILoggerFactory>();
            var log           = loggerFactory.CreateLogger <Startup>();

            //Initialize the static AutoMapper
            Mapper.Initialize(cfg => cfg.AddMaps(typeof(Startup)));

            // DATABASE SETUP
            log.LogInformation("Fetching the application's database context ...");

            var adminCtx = new EmbcDbContext(new DbContextOptionsBuilder <EmbcDbContext>()
                                             .UseLoggerFactory(loggerFactory)
                                             .UseSqlServer(DatabaseTools.GetSaConnectionString(Configuration)).Options);

            if (Configuration.DbFullRefresh())
            {
                log.LogWarning("DROPPING the database! ...");
                adminCtx.Database.EnsureDeleted();
            }

            log.LogInformation("Initializing the database ...");
            if (!string.IsNullOrEmpty(Configuration["DB_ADMIN_PASSWORD"]))
            {
                //For OpenShift deployments
                DatabaseTools.CreateDatabaseIfNotExists(DatabaseTools.GetSaConnectionString(Configuration, "master"),
                                                        Configuration["DB_DATABASE"],
                                                        Configuration["DB_USER"],
                                                        Configuration["DB_PASSWORD"]);
            }

            //Check if the database exists
            var databaseExists = adminCtx.Database.CanConnect();

            if (databaseExists)
            {
                log.LogInformation("Syncing migrations prior to migrating...");
                DatabaseTools.SyncInitialMigration(DatabaseTools.GetSaConnectionString(Configuration));
            }

            log.LogInformation("Migrating the database ...");
            adminCtx.Database.Migrate();

            log.LogInformation("The database migration is complete.");

            try
            {
                // run the database seeders
                log.LogInformation("Adding/Updating seed data ...");

                ISeederRepository seederRepository = new SeederRepository(adminCtx);
                var seedDataLoader = new SeedDataLoader(loggerFactory);
                var seeder         = new EmbcSeeder(loggerFactory, seederRepository, env, seedDataLoader);
                seeder.SeedData();

                log.LogInformation("Seeding operations are complete.");
            }
            catch (Exception e)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendLine("The database setup failed!");
                msg.AppendLine("The database may not be available and the application will not function as expected.");
                msg.AppendLine("Please ensure a database is available and the connection string is correct.");
                msg.AppendLine("If you are running in a development environment, ensure your test database and server configuration match the project's default connection string.");
                msg.AppendLine("Error message is " + e.Message);
                log.LogCritical(new EventId(-1, "Database Seeding Failed"), e, msg.ToString());
            }

            string pathBase = Configuration["BASE_PATH"];

            if (!string.IsNullOrEmpty(pathBase))
            {
                app.UsePathBase(pathBase);
            }
            if (!env.IsProduction())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.Use(async(ctx, next) =>
            {
                ctx.Response.Headers.Add("Content-Security-Policy",
                                         "script-src 'self' 'unsafe-eval' 'unsafe-inline' https://apis.google.com https://maxcdn.bootstrapcdn.com https://cdnjs.cloudflare.com https://code.jquery.com https://stackpath.bootstrapcdn.com https://fonts.googleapis.com");
                ctx.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
                await next();
            });
            app.UseXContentTypeOptions();
            app.UseXfo(xfo => xfo.Deny());

            StaticFileOptions staticFileOptions = new StaticFileOptions();

            staticFileOptions.OnPrepareResponse = ctx =>
            {
                ctx.Context.Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, private";
                ctx.Context.Response.Headers[HeaderNames.Pragma]       = "no-cache";
                ctx.Context.Response.Headers["X-Frame-Options"]        = "SAMEORIGIN";
                ctx.Context.Response.Headers["X-XSS-Protection"]       = "1; mode=block";
                ctx.Context.Response.Headers["X-Content-Type-Options"] = "nosniff";
            };

            app.UseStaticFiles(staticFileOptions);
            app.UseSpaStaticFiles(staticFileOptions);
            app.UseXXssProtection(options => options.EnabledWithBlockMode());
            app.UseNoCacheHttpHeaders();
            // IMPORTANT: This session call MUST go before UseMvc()
            var sessionTimout = TimeSpan.FromMinutes(Configuration.ServerTimeoutInMinutes());

            app.UseSession(new SessionOptions()
            {
                IdleTimeout = sessionTimout
            });
            app.UseAuthentication();

            // global policy - assign here or on each controller
            // IMPORTANT: Make sure UseCors() is called BEFORE UseMvc()
            app.UseCors("AllowAnyOrigin");

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core, see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                // Only run the angular CLI Server in Development mode (not staging or test.)
                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }