예제 #1
0
        public void Default_ContextSeeder_Creates_No_Null_MockCollections()
        {
            var           seeder = new ContextSeeder <SimpleContext>();
            SimpleContext db     = seeder.SeedDatabase();

            Assert.IsTrue(db.Customers.All(c => c != null));
            Assert.IsTrue(db.Products.All(c => c != null));
        }
예제 #2
0
        public void Default_ContextSeeder_Creates_Data()
        {
            var           seeder = new ContextSeeder <SimpleContext>();
            SimpleContext db     = seeder.SeedDatabase();

            Assert.IsTrue(db.Customers.Count == 30);
            Assert.IsTrue(db.Products.Count == 30);
        }
예제 #3
0
        public void ContexSeeder_Returns_Empty_MockContext()
        {
            var           seeder = new ContextSeeder <SimpleContext>();
            SimpleContext db     = seeder.SeedDatabase(0);

            Assert.IsNotNull(db);
            Assert.IsTrue(db.Customers.Count == 0);
        }
예제 #4
0
        public void ContextSeeder_Uses_Correct_Default_Class_Seeders_With_SimpleContext()
        {
            var seeder = new ContextSeeder <SimpleContext>();
            var db     = seeder.SeedDatabase(1);

            Assert.IsTrue(seeder.ClassSeeders.ContainsKey("Customers"));
            Assert.IsTrue(seeder.ClassSeeders.ContainsKey("Products"));
            Assert.IsTrue(seeder.ClassSeeders.Count == 2);
        }
예제 #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //app.UseHttpsRedirection();
            app.UseRouting();

            app.UseCors(ops =>
            {
                ops.AllowAnyMethod();
                ops.AllowAnyOrigin();
                ops.AllowAnyHeader();
            });


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


            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "APTracker API V1"); });

            using var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope();
            var context = serviceScope.ServiceProvider.GetRequiredService <AppDbContext>();

            context.Database.Migrate();
            ContextSeeder.SeedDatabase(context);
        }