Ejemplo n.º 1
0
        private void Run()
        {
            int    version = Options.TargetVersion ?? -1;
            string mode    = (Options.Mode ?? "manual").ToLower();

            if (mode == "script")
            {
                RunScript(version);
                return;
            }
            if (mode == "auto")
            {
                var runner = new Runner(SharpFactory.Default.CreateDataClient(), GetAssemblyWithMigrations());
                runner.MigrationGroup = Options.MigrationGroup;
                runner.Run(version);
                return;
            }
            if (mode == "seed")
            {
                if (String.IsNullOrEmpty(Options.SeedName))
                {
                    Exit("Please, set the seed name");
                    return;
                }
                var seedRunner = new SeedRunner(SharpFactory.Default.CreateDataClient(), GetAssemblyWithMigrations());
                seedRunner.Run(Options.SeedName, Options.SeedArgs, Options.MigrationGroup);
                return;
            }
            var crunner = new ConsoleRunner(SharpFactory.Default.ConnectionString, SharpFactory.Default.DataProviderName);

            crunner.AssemblyWithMigrations = GetAssemblyWithMigrations();
            crunner.MigrationGroup         = Options.MigrationGroup;
            crunner.Start();
        }
Ejemplo n.º 2
0
        public void Seed(SeedOptions options)
        {
            Prepare(options, "Seed");
            var seedRunner = new SeedRunner(SharpFactory.Default.CreateDataClient(), GetAssemblyWithMigrations(options));

            seedRunner.Run(options.SeedName, options.SeedArgs);
        }
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureServices(services =>
            {
                services.AddDbContextPool <IssueTrackerDbContext>(options =>
                {
                    options.UseInMemoryDatabase("InMemoryAppDb");

                    options.UseInternalServiceProvider(
                        new ServiceCollection()
                        .AddEntityFrameworkInMemoryDatabase()
                        .BuildServiceProvider()
                        );
                }, 1);

                ServiceProvider serviceProvider = services.BuildServiceProvider();

                using IServiceScope scope                 = serviceProvider.CreateScope();
                IServiceProvider scopedServices           = scope.ServiceProvider;
                IssueTrackerDbContext applicationDatabase = scopedServices.GetRequiredService <IssueTrackerDbContext>();

                ILogger <IntegrationTestWebAppFactory <TStartup> > logger = scopedServices.GetRequiredService <ILogger <IntegrationTestWebAppFactory <TStartup> > >();

                // Belum Ketemu Destroy DB Test Sebelumnya dari Memory,
                // DB Context Singleton Pool
                try
                {
                    applicationDatabase.Database.EnsureDeleted();

                    applicationDatabase.Database.EnsureCreated();
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occured while preparing test database. Info: {ex.Message}");
                }

                try
                {
                    SeedRunner.Run(applicationDatabase);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "An error occured while populating test data. Info: {ex.Message}");
                }
            });
        }
Ejemplo n.º 4
0
 public void Should_throw_when_seed_not_found()
 {
     _seedRunner.Run("someseed");
 }
Ejemplo n.º 5
0
 public void Should_throw_when_seed_not_found()
 {
     Assert.Throws <SeedNotFoundException>(() => _seedRunner.Run("someseed"));
 }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IssueTrackerDbContext dbContext, ILoggerFactory loggerFactory)
        {
            AppConfig appConfig = Configuration.GetSection("AppConfig").Get <AppConfig>();

            List <AppLoggerConfiguration> loggerConfigs = new List <AppLoggerConfiguration> {
                new AppLoggerConfiguration {
                    LogLevel = LogLevel.Error,
                    EventId  = 0,
                },
                new AppLoggerConfiguration {
                    LogLevel = LogLevel.Warning,
                    EventId  = 0,
                },
            };

            loggerConfigs.ForEach(item =>
            {
                using AppLoggerProvider logger = new AppLoggerProvider(item, dbContext);

                loggerFactory?.AddProvider(logger);
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                app.UseSwagger(u =>
                {
                    u.SerializeAsV2 = true;
                });

                app.UseSwaggerUI(u =>
                {
                    u.SwaggerEndpoint("/swagger/v1/swagger.json", "Issue Tracker API");
                });

                // TIDAK DIREKOMENDASIKAN AUTO MIGRATE DI PRODUCTION
                // KARENA BELUM TENTU HANDLE MIGRASI DATA & RUN APPS NYA LAMA

                dbContext?.Database.Migrate();

                SeedRunner.Run(dbContext);
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            if (appConfig.UseHttps)
            {
                app.UseHttpsRedirection();
            }

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseJwtInCookie();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }