/// <summary> /// Initialize the test database fixture. /// </summary> public DatabaseFixture() { // Create a new application db context this.Context = new ApplicationDbContext(); // Build the database for testing DbBuilder.Rebuild(Context); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationDbContext context, IServiceProvider serviceProvider, IOptions <SecureAppConfig> secureConfig) { //Save reference to the mail client //MailClient.Client = serviceProvider.GetService<SparkPostClient>(); loggerFactory.AddConsole(Program.FileConfig.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseStatusCodePagesWithRedirects("/Home/Error"); app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseGoogleAuthentication(new GoogleOptions() { ClientId = secureConfig.Value.GoogleClientId, ClientSecret = secureConfig.Value.GoogleClientSecret }); app.UseCors("AllowEverything"); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); #if DEBUG // Seed database if not running in production if (Program.AppConfig.DatabaseReset) { DbBuilder.Rebuild(context); } #endif }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context) { // Set the environment based on the appsettings.json Program.SetEnvironment(env); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseAuthentication(); // Serve backend files app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "./wwwroot") ), RequestPath = "" }); // Determine which hosts are allowed, for proper CORS configuration AppConfig config = new AppConfig(); String[] allowedHosts = config.GetProperty("Web.AllowedHosts").Split(','); // Report the hosts we're allowing CORS on foreach (String host in allowedHosts) { Console.WriteLine("Allowing CORS request for: {0}", host); } // Configure CORS with the proper hosts app.UseCors(corsPolicyBuilder => corsPolicyBuilder.WithOrigins(allowedHosts) .AllowAnyMethod() .AllowAnyHeader() ); // TODO: remove this when we're done with it /* // Create a new example group */ /* var group = new Group(); */ /* group.Name = "My new fancy group"; */ /* context.Groups.Add(group); */ /* context.SaveChanges(); */ // Define the routes app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}" ); }); /* // TODO: reenable this once the DbBuilder is complete */ /* // Seed database if not running in production */ if (Program.AppConfig.DatabaseReset) { DbBuilder.Rebuild(context); } }