예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IBackgroundJobClient backgroundJobs, IRecurringJobManager recurringJob, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/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();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
                    {
                        RequireSsl         = false,
                        SslRedirect        = false,
                        LoginCaseSensitive = true,
                        Users = new []
                        {
                            new BasicAuthAuthorizationUser
                            {
                                Login         = Configuration.GetValue <string>("HangFire:Username"),
                                PasswordClear = Configuration.GetValue <string>("HangFire:Password"),
                            }
                        }
                    }) }
            });

            var cron = new CronHelpers(context);

            recurringJob.AddOrUpdate("CleanInvestmentsJob", Job.FromExpression(() => cron.AwardInvestmentProfits()), Cron.Daily(17));
            recurringJob.AddOrUpdate("CleanEspionagesJob", Job.FromExpression(() => cron.RemoveEspionageInvestments()), Cron.Daily(17));

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

            app.UseOpenApi();
            app.UseSwaggerUi3();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
        public void RemoveEspionageInvestments_RemoveOldInvestments()
        {
            var config  = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            var context = ApplicationDbContextFactory.CreateDbContext(config);

            var helper = new CronHelpers(context);

            try
            {
                helper.RemoveEspionageInvestments();
                Assert.IsTrue(true);
            }
            catch
            {
                Assert.Fail();
            }
        }