Exemple #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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    var context = serviceScope.ServiceProvider.GetRequiredService <StoreContext>();
                    SampleDataInitializer.InitializeData(context);
                }
            }

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "SpyStore Service v1");
            });
            app.UseCors("AllowAll");

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

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();//.RequireCors("AllowAll");
            });
        }
Exemple #2
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() || env.IsEnvironment("Local"))
            {
                app.UseDeveloperExceptionPage();
                using (var serviceScope = app.ApplicationServices
                                          .GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    SampleDataInitializer.InitializeData(
                        serviceScope.ServiceProvider.GetRequiredService <StoreContext>());
                }
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
 public SearchServiceTests()
 {
     RootAddressProductController = "api/products";
     RootAddressAdminController   = "api/admin";
     RootAddressOrderController   = "api/orders";
     SampleDataInitializer.InitializeData(new BEIdentityContextFactory().CreateDbContext(null));
 }
Exemple #4
0
        public void ShouldClearAndReseedTheDatabase()
        {
            SampleDataInitializer.InitializeData(Context);
            var cars = Context.Cars.IgnoreQueryFilters().ToList();

            Assert.Equal(9, cars.Count);
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                using (var serviceScope = app.ApplicationServices
                                          .GetRequiredService <IServiceScopeFactory>()
                                          .CreateScope())
                {
                    var context = serviceScope.ServiceProvider.GetRequiredService <StoreContext>();
                    SampleDataInitializer.InitializeData(context);
                }
            }

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "SpyStore Service v1");
            });
            app.UseStaticFiles();

            //needed by JavaScript frameworks
            app.UseCors("AllowAll");

            app.UseMvc();
        }
Exemple #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,
     ApplicationDbContext context)
 {
     if (env.IsDevelopment())
     {
         // If in development environment, display debug info
         app.UseDeveloperExceptionPage();
     }
     // Initialize the database
     if (Configuration.GetValue <bool>("RebuildDataBase"))
     {
         SampleDataInitializer.InitializeData(context);
     }
     // redirect http traffic to https
     app.UseHttpsRedirection();
     // opt-in to routing
     app.UseRouting();
     // enable authorization checks
     app.UseAuthorization();
     // opt-in to use endpoint routing
     app.UseEndpoints(endpoints =>
     {
         // use attribute routing on controllers
         endpoints.MapControllers();
     });
 }
Exemple #7
0
        public OrderTests()
        {
            var storeContextFactory = new StoreContextFactory();

            SampleDataInitializer.InitializeData(storeContextFactory.CreateDbContext(new string[0]));
            _db = storeContextFactory.CreateDbContext(new string[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();
                //Initialize the database
                if (Configuration.GetValue <bool>("RebuildDataBase"))
                {
                    SampleDataInitializer.InitializeData(context);
                }
            }
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "AutoLot Service v1");
            });

            //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
            app.UseEndpoints(endpoints =>
            {
                //use attribute routing on controllers
                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() || env.IsEnvironment("Local"))
            {
                app.UseDeveloperExceptionPage();
                //using var serviceScope =
                //    app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
                //var context = serviceScope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
                if (Configuration.GetValue <bool>("RebuildDataBase"))
                {
                    SampleDataInitializer.InitializeData(context);
                }
            }
            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();
            }

            app.UseHttpsRedirection();
            app.UseWebOptimizer();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });
        }
 public OrderTests()
 {
     _db = new StoreContextFactory().CreateDbContext(new string[0]);
     _db.CustomerId = 1;
     //Have to load database with different context, OR call reload on each entity
     SampleDataInitializer.InitializeData(new StoreContextFactory().CreateDbContext(new string[0]));
 }
        public ShoppingCartRepoTests()
        {
            var context = new StoreContextFactory().CreateDbContext(null);
            _repo = new ShoppingCartRepo(context,new ProductRepo(context),new CustomerRepo(context);
            SampleDataInitializer.InitializeData(_repo.Context);

        }
Exemple #12
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() || _env.EnvironmentName == "Local")
            {
                app.UseDeveloperExceptionPage();
                using var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope();
                var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                SampleDataInitializer.InitializeData(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.UseWebOptimizer();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                //endpoints.MapControllerRoute(
                //    name: "default",
                //    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemple #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment() || env.IsEnvironment("Local"))
            {
                app.UseDeveloperExceptionPage();
                using (var serviceScope = app.ApplicationServices
                                          .GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    SampleDataInitializer
                    .InitializeData(serviceScope.ServiceProvider.GetRequiredService <StoreContext>());
                }
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseWebOptimizer();
            app.UseStaticFiles();
            //app.UseCookiePolicy();

            //app.UseMvcWithDefaultRoute();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Products}/{action=Index}/{id?}");
            });
        }
        public void ShouldDropAndRecreateTheDatabaseThenLoadData()
        {
            SampleDataInitializer.InitializeData(Context);
            var cars = Context.Cars.IgnoreQueryFilters().ToList();

            Assert.Equal(9, cars.Count);
        }
Exemple #15
0
        public void ShouldClearTheData()
        {
            SampleDataInitializer.InitializeData(Context);
            SampleDataInitializer.ClearData(Context);
            var cars = Context.Cars.IgnoreQueryFilters();

            Assert.Empty(cars);
        }
        static void Main(string[] args)
        {
            using var context = new ApplicationDbContextFactory().CreateDbContext(new string[0]);
            SampleDataInitializer.InitializeData(context);
            var orders = context.CustomerOrderViewModels.ToList();

            foreach (var order in orders)
            {
                Console.WriteLine(order.ToString());
            }
        }
 public void ShouldLoadCategoriesAndProducts()
 {
     SampleDataInitializer.DropAndCreateDatabase(Context);
     SampleDataInitializer.InitializeData(Context);
     Assert.Equal(7, Context.Categories.Count());
     Assert.Equal(41, Context.Products.Count());
     Assert.Equal(1, Context.Customers.Count());
     Context.CustomerId = Context.Customers.First().Id;
     Assert.Equal(1, Context.Orders.Count());
     Assert.Equal(3, Context.OrderDetails.Count());
     Assert.Equal(1, Context.ShoppingCartRecords.Count());
     SampleDataInitializer.DropAndCreateDatabase(Context);
 }
        public void ShouldClearTheData()
        {
            SampleDataInitializer.InitializeData(Context);
            var cars = Context.Cars.IgnoreQueryFilters().ToList();

            Assert.NotNull(cars);
            Assert.Equal(9, cars.Count);
            SampleDataInitializer.ClearData(Context);
            var cars2 = Context.Cars.IgnoreQueryFilters();

            Assert.NotNull(cars2);
            Assert.Empty(cars2);
        }
Exemple #19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    var context = serviceScope.ServiceProvider.GetRequiredService <StoreContext>();
                    SampleDataInitializer.InitializeData(context);
                }
            }

            app.UseCors("AllowAll");  // has to go before UseMvc
            app.UseMvc();
        }
        // 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,
                              SampleDataInitializer sampleData)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                // Configure the HTTP request pipeline.
                // Add the console logger.
                loggerfactory.AddConsole(minLevel: LogLevel.Warning);
            }
            if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
            {
                //app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                //app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            app.UseCookiePolicy();


            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });

            // Add Sample Data
            sampleData.InitializeData();
        }
Exemple #21
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 //This method is used to set up the application to respond to HTTP requests.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
         //Database Initialization Code
         using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
         {
             var context = serviceScope.ServiceProvider.GetRequiredService <StoreContext>();
             SampleDataInitializer.InitializeData(context);
         }
     }
     app.UseSwagger();
     app.UseSwaggerUI(c =>
     {
         c.SwaggerEndpoint("/swagger/v1/swagger.json", "SpyStore Service v1");
     });
     app.UseStaticFiles();
     //Needed by JavaScript frameworks used later in the book. For more information on Cross-Origin Requests CORS
     //support: https://docs.microsoft.com/en-us/aspnet/core/security/cors.
     app.UseCors("AllowAll"); //has to go before UseMVC
     app.UseMvc();
 }
Exemple #22
0
 protected void ResetTheDatabase()
 {
     SampleDataInitializer.InitializeData(new StoreContextFactory().CreateDbContext(null));
 }
 public OrdersControllerTests()
 {
     RootAddress = "api/orders";
     SampleDataInitializer.InitializeData(new StoreContextFactory().CreateDbContext(null));
 }
 public PlaceOrderServiceTests()
 {
     RootAddressOrderController = "api/orders";
     SampleDataInitializer.InitializeData(new BEIdentityContextFactory().CreateDbContext(null));
 }
Exemple #25
0
 public OrderRepoTests()
 {
     _repo = new OrderRepo(new OrderDetailRepo());
     SampleDataInitializer.InitializeData(_repo.Context);
 }
 protected void LoadDatabase()
 {
     SampleDataInitializer.InitializeData(Db);
 }
Exemple #27
0
 public CustomerRepoGetTests()
 {
     _repo = new CustomerRepo();
     SampleDataInitializer.ClearData(_repo.Context);
     SampleDataInitializer.InitializeData(_repo.Context);
 }
 public ShoppingCartRecordControllerNoUpdateTests()
 {
     RootAddress = "api/shoppingcartrecord";
     SampleDataInitializer.InitializeData(new StoreContextFactory().CreateDbContext(null));
     var foo = "foo";
 }
 public ShoppingCartServiceTests()
 {
     RootAddressCartLineController = "api/Cartline";
     SampleDataInitializer.InitializeData(new BEIdentityContextFactory().CreateDbContext(null));
 }
Exemple #30
0
 public ProductRepoTests()
 {
     _repo = new ProductRepo();
     SampleDataInitializer.InitializeData(_repo.Context);
 }