Example #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, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                //If in development environment, display debug info
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AutoLot.Api v1"));
                //Initialize the database
                if (Configuration.GetValue <bool>("RebuildDataBase"))
                {
                    SampleDataInitializer.ClearAndReseedDatabase(context);
                }
            }

            //redirect http traffic to https
            app.UseHttpsRedirection();
            //opt-in to routing
            app.UseRouting();

            //Add CORS Policy
            app.UseCors("AllowAll");

            //enable authorization checks
            app.UseAuthorization();
            //opt-in to using endpoint routing
            //use attribute routing on controllers
            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                if (Configuration.GetValue <bool>("RebuildDataBase"))
                {
                    SampleDataInitializer.ClearAndReseedDatabase(context);
                }
            }
            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.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                //endpoints.MapControllerRoute(
                //    name: "default",
                //    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        public void ShouldReseedTheTables()
        {
            SampleDataInitializer.ClearAndReseedDatabase(Context);
            var cars = Context.Cars.IgnoreQueryFilters().ToList();

            Assert.NotNull(cars);
            Assert.Equal(9, cars.Count);
        }
        public EnsureAutoLotDatabaseTestFixture()
        {
            var configuration = TestHelpers.GetConfiguration();
            var context       = TestHelpers.GetContext(configuration);

            SampleDataInitializer.ClearAndReseedDatabase(context);
            context.Dispose();
        }