Esempio n. 1
0
        public OrderTests()
        {
            var storeContextFactory = new StoreContextFactory();

            StoreDataInitializer.InitializeData(storeContextFactory.CreateDbContext(new string[0]));
            _db = storeContextFactory.CreateDbContext(new string[0]);
        }
Esempio n. 2
0
        // 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)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //app.UseBrowserLink();
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>()
                                          .CreateScope())
                {
                    StoreDataInitializer.InitializeData(app.ApplicationServices);
                }
            }
            else
            {
                app.UseExceptionHandler("/Products/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Products}/{action=Index}/{id?}");
            });
        }
Esempio n. 3
0
        public OrderRepoTests()
        {
            _repo = new OrderRepo(new OrderDetailRepo());
            StoreDataInitializer.ClearData(_repo.Context);
            StoreDataInitializer.InitializeData(_repo.Context);

        }
 protected override void CleanDatabase()
 {
     using (StoreContext storeContext = new StoreContext())
     {
         StoreDataInitializer.ClearData(storeContext);
     }
 }
        // 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)

        {
            if (env.IsDevelopment())

            {
                loggerFactory.AddConsole(Configuration.GetSection("Logging"));

                loggerFactory.AddDebug();
            }



            if (env.IsDevelopment())

            {
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())

                {
                    StoreDataInitializer.InitializeData(app.ApplicationServices);
                }
            }

            app.UseCors("AllowAll");  // has to go before UseMvc



            app.UseMvc();
        }
Esempio n. 6
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();
                app.UseBrowserLink();
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>()
                                          .CreateScope())
                {
                    StoreDataInitializer.InitializeData(serviceScope.ServiceProvider.GetRequiredService <StoreContext>());
                }
            }
            else
            {
                app.UseExceptionHandler("/Products/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Products}/{action=Index}/{id?}");
            });
        }
 public OrderTests() : base()
 {
     using (StoreContext storeContext = new StoreContext())
     {
         StoreDataInitializer.ClearData(storeContext);
         StoreDataInitializer.InitializeData(storeContext);
     }
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var _repo = new ShoppingCartRepo(new ProductRepo());

            //StoreDataInitializer.ClearData(_repo.Context);
            StoreDataInitializer.InitializeData(_repo.Context);
            Console.ReadLine();
        }
        protected override void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    StoreDataInitializer.ClearData(_repo.Context);
                    _repo.Dispose();
                }

                disposedValue = true;
                base.Dispose(disposing);
            }
        }
Esempio n. 10
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()) {
                    StoreDataInitializer.InitializeData(serviceScope.ServiceProvider);
                }
            }

            app.UseCors("AllowAll");
            app.UseMvc();
        }
Esempio n. 11
0
        // 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)
        {
            // _env = env;

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                loggerFactory
                .AddConsole(Configuration.GetSection("Logging"))
                .AddDebug();

                StoreDataInitializer.InitializeData(app.ApplicationServices);
            }

            app.UseCors("AllowAll");


            app.UseMvc();
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddMvc();
            services
            .AddMvcCore(config => config.Filters.Add(new SpyStoreExceptionFilter(HostingEnvironment.IsDevelopment())))
            .AddJsonFormatters(j =>
            {
                j.ContractResolver = new DefaultContractResolver();
                j.Formatting       = Formatting.Indented;
            })
            ;

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll", builder =>
                {
                    builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials();
                });
            });

            string connectionString = Configuration.GetConnectionString("SpyStore");

            services.AddDbContext <StoreContext>(
                options => options.UseSqlServer(connectionString));

            services.AddScoped <ICategoryRepo, CategoryRepo>();
            services.AddScoped <IProductRepo, ProductRepo>();
            services.AddScoped <ICustomerRepo, CustomerRepo>();
            services.AddScoped <IShoppingCartRepo, ShoppingCartRepo>();
            services.AddScoped <IOrderRepo, OrderRepo>();
            services.AddScoped <IOrderDetailRepo, OrderDetailRepo>();

            // Build the intermediate service provider
            var serviceProvider = services.BuildServiceProvider();

            StoreDataInitializer.InitializeData(serviceProvider);
        }
 public void Dispose()
 {
     StoreDataInitializer.ClearData(_db);
     _db.Dispose();
 }
 public OrderTests()
 {
     _db = new StoreContext();
     StoreDataInitializer.InitializeData(_db);
 }
 public override void Dispose()
 {
     StoreDataInitializer.InitializeData(new StoreContext());
 }
Esempio n. 16
0
 public void Dispose()
 {
     StoreDataInitializer.ClearData(_repo.Context);
     _repo.Dispose();
 }
Esempio n. 17
0
 public ShoppingCartRepoTests()
 {
     _repo = new ShoppingCartRepo(new ProductRepo());
     StoreDataInitializer.ClearData(_repo.Context);
     StoreDataInitializer.InitializeData(_repo.Context);
 }
 public void Dispose()
 {
     StoreDataInitializer.ClearData(new StoreContext());
     _db.Dispose();
 }
Esempio n. 19
0
 public ProductRepoTests()
 {
     _repo = new ProductRepo();
     StoreDataInitializer.ClearData(_repo.Context);
     StoreDataInitializer.InitializeData(_repo.Context);
 }
Esempio n. 20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseWebOptimizer();
            app.UseWebSockets();
            app.Use(async(context, next) =>
            {
                if (context.Request.Path == "/ws")
                {
                    if (context.WebSockets.IsWebSocketRequest)
                    {
                        WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
                        await Echo(context, webSocket);
                    }
                    else
                    {
                        context.Response.StatusCode = 400;
                    }
                }
                else
                {
                    await next();
                }
            });
            app.UseFileServer();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>()
                                          .CreateScope())
                {
                    var context = serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                    StoreDataInitializer.InitializeData(context);
                }
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

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

            app.UseAuthentication();

            //URL Rewrite Middleware
            //using (StreamReader apacheModRewriteStreamReader = File.OpenText("ApacheModRewrite.txt"))
            //using (StreamReader iisUrlRewriteStreamReader = File.OpenText("IISUrlRewrite.xml"))
            //{
            var rwOptions = new RewriteOptions()
                            .AddRedirect("foo", "Products/Featured", 302) //status is optional, defaults to 302
                            .AddRedirect("(Products/)([^FfPp0-9].*)", "$1Featured")
                            .AddRewrite("bar", "Products/Featured", skipRemainingRules: true)
                            .Add(RedirectXmlRequests);

            //.AddRedirectToHttps(302, 63812) //Force SSL
            //.AddApacheModRewrite(apacheModRewriteStreamReader)
            //.AddIISUrlRewrite(iisUrlRewriteStreamReader);

            app.UseRewriter(rwOptions);
            //}

            //app.UseMvcWithDefaultRoute();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Esempio n. 21
0
 private void CleanDatabase()
 {
     StoreDataInitializer.ClearData(_db);
 }
 public ShoppingCartControllerNoUpdateTests()
 {
     RootAddress = "api/shoppingcart";
     StoreDataInitializer.InitializeData(new StoreContext());
 }