// 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 ShouldDropAndCreateTheDatabase() { SampleDataInitializer.DropAndCreateDatabase(Context); var cars = Context.Cars.IgnoreQueryFilters(); Assert.Empty(cars); }
// 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(); app.UseCors("AllowAll"); app.UseMvc(); }
public SearchServiceTests() { RootAddressProductController = "api/products"; RootAddressAdminController = "api/admin"; RootAddressOrderController = "api/orders"; SampleDataInitializer.InitializeData(new BEIdentityContextFactory().CreateDbContext(null)); }
protected void CreateCategoryAndProducts(StoreContext context) { SampleDataInitializer.ClearData(context); var prod1 = new Product { CurrentPrice = 12.99M, UnitCost = 10.99M, UnitsInStock = 5, Details = { ModelName = "Product 1" }, }; var prod2 = new Product { CurrentPrice = 99.99M, UnitCost = 89.99M, UnitsInStock = 2, Details = { ModelName = "Product 2" } }; var cat = new Category { CategoryName = "CatName" }; cat.Products.AddRange(new List <Product> { prod1, prod2 }); context.Categories.Add(cat); context.SaveChanges(); }
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])); }
// 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?}"); }); }
public void ShouldAddAnObjectGraph() { var prod = new Product { CurrentPrice = 12.99M, UnitCost = 10.99M, UnitsInStock = 5, }; var cat = new Category { CategoryName = "CatName" }; ExecuteInATransaction(RunTheTest); void RunTheTest() { SampleDataInitializer.ClearData(Context); cat.Products.Add(prod); Assert.Equal(0, cat.Id); Assert.Equal(0, prod.CategoryId); Assert.Equal(0, prod.Id); Context.Categories.Add(cat); Assert.True(cat.Id == 0); Assert.True(prod.CategoryId == 0); Assert.Equal(cat.Id, prod.CategoryId); Context.SaveChanges(); Assert.Single(Context.Categories); Assert.Single(Context.Products); Assert.True(cat.Id > 0); Assert.True(prod.Id > 0); Assert.Equal(cat.Id, prod.CategoryId); } }
// 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 void ShouldDropAndRecreateTheDatabaseThenLoadData() { 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, 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"); }); }
public void ShouldAddListOfNewCategoryRecords() { var cats = new List <Category> { new Category { CategoryName = "Cat1Name" }, new Category { CategoryName = "Cat2Name" }, new Category { CategoryName = "Cat3Name" }, }; ExecuteInATransaction(RunTheTest); void RunTheTest() { SampleDataInitializer.ClearData(Context); Context.Categories.AddRange(cats); Context.SaveChanges(); Assert.Equal(3, Context.Categories.Count()); } }
// 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(); }); }
// 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(); //Original code //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); } } 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 //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, 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.UseStaticFiles(); //app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Products}/{action=Index}/{id?}"); }); }
public void ShouldClearAndReseedTheDatabase() { SampleDataInitializer.InitializeData(Context); var cars = Context.Cars.IgnoreQueryFilters().ToList(); Assert.Equal(9, cars.Count); }
public ShoppingCartRepoTests() { var context = new StoreContextFactory().CreateDbContext(null); _repo = new ShoppingCartRepo(context,new ProductRepo(context),new CustomerRepo(context); SampleDataInitializer.InitializeData(_repo.Context); }
public void ShouldClearTheData() { SampleDataInitializer.InitializeData(Context); SampleDataInitializer.ClearData(Context); var cars = Context.Cars.IgnoreQueryFilters(); Assert.Empty(cars); }
public EnsureAutoLotDatabaseTestFixture() { var configuration = TestHelpers.GetConfiguration(); var context = TestHelpers.GetContext(configuration); SampleDataInitializer.ClearAndReseedDatabase(context); context.Dispose(); }
public void ShouldReseedTheTables() { SampleDataInitializer.ClearAndReseedDatabase(Context); var cars = Context.Cars.IgnoreQueryFilters().ToList(); Assert.NotNull(cars); Assert.Equal(9, cars.Count); }
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); }
public static void SeedDatabase(IHostingEnvironment hostingEnvironment, AspergillosisContext context) { SampleDataInitializer.Initialize(context); SampleDataInitializer.AddDefaultPatientStatuses(context); SampleDataInitializer.CreateDbImportTypes(context); SampleDataInitializer.AddIgTypes(context); RadiologyDataInitializer.AddRadiologyModels(context); CaseReportFormsDataInitializer.AddCaseReportFormsModels(context); QoLExcelImportType.Seed(context); IGgEPRImportTypeSeed.Seed(context); CaseReportFormsDataInitializer.AddSelectFieldTypes(context); MedicalTiralsDataInitializer.AddMedicalTrialsModels(context); IntraDrugLevelExcelTypeSeed.Seed(context); UnitOfMeasureMgLSeed.Seed(context); ManArtsImportSeed.Seed(context); ManArtsImportSeed.AddOtherPFTs(context); ManArtsProcessedFileSeed.Seed(context); ManArtsProcessedFileSeed.SeedSmokingStatuses(context); ManArtsProcessedFileSeed.SeedDrugLevel(context); ManArtsProcessedFileSeed.SeedPFTandHaematology(context); EPRClinicLetterDbImportTypeSeed.Seed(context); FoodDatabaseSeed.SeedDefaultFoods(context); OtherAllergicItemDatabaseSeed.SeedDefaultItems(context); FungiAllergicItemDatabaseSeed.SeedDefaultItems(context); ReportTypeSeed.Initialize(context); DLNACDatesImportTypeSeed.Seed(context); EPRTotalIgEImportTypeSeed.Seed(context); UnitOfMeasureMgLSeed.SeedOtherUnits(context); TestTypeSeed.Seed(context); PatientTestsResultsImportTypeSeed.CRPSeed(context); PatientTestsResultsImportTypeSeed.AlbuminSeed(context); PatientTestsResultsImportTypeSeed.HbSeed(context); PatientTestsResultsImportTypeSeed.WBCSeed(context); PatientTestsResultsImportTypeSeed.LymphocytesSeed(context); QoLExcelImportType.SeedMRC(context); ReportTypeSeed.AddCPAMortalityAudit(context); ReportTypeSeed.AddIgGAndSGRQReport(context); AllTestTypesSeed.Seed(context); RadiologyDataInitializer.OtherRadiologyTypes(context, hostingEnvironment); PFTSpreadsheetImproterTypeSeed.Seed(context); ReferallDatesImportTypeSeed.Run(context); AddHospitalAdmissionDbImportType.Seed(context); DateOfDiagnosisDbImportType.Seed(context); AddMortalityAuditDates.Seed(context); AddMortalityAuditSGRQ.Seed(context); AddMortalityAuditMRCScore.Seed(context); AddMortalityAuditWeightAndHeight.Seed(context); //PostcodeSeed.ReadCsvIntoDatabase(hostingEnvironment, context); }
// 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(); }
public void ShouldAddNewCategoryRecord() { var cat = new Category { CategoryName = "CatName" }; ExecuteInATransaction(RunTheTest); void RunTheTest() { SampleDataInitializer.ClearData(Context); Context.Categories.Add(cat); Context.SaveChanges(); Assert.Single(Context.Categories.ToList()); } }
// 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) { //var result = string.IsNullOrEmpty(_testSecret) ? "Null" : "Not Null"; //app.Run(async (context) => //{ // await context.Response.WriteAsync($"Secret is {result}"); //}); app.UseSession(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); #pragma warning disable CS0618 // 类型或成员已过时 app.UseIdentity(); #pragma warning restore CS0618 // 类型或成员已过时 // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Loading sample data. using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory> ().CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetService <BestStoreDbContext> (); bool HasCreated = dbContext.Database.EnsureCreated(); if (HasCreated) { SampleDataInitializer dbInitializer = new SampleDataInitializer(dbContext); dbInitializer.LoadBasicInformationAsync().Wait(); dbInitializer.LoadSampleDataAsync().Wait(); } } }
// 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(); }
public void ShouldGetOrderWithDetails() { ExecuteInATransaction(RunTheTest); void RunTheTest() { ResetContext(); SampleDataInitializer.ClearData(Context); CreateCategoryAndProducts(); var cust = new Customer() { EmailAddress = "*****@*****.**", FullName = "Ful Name", Password = "******" }; var order = new Order { OrderDate = DateTime.Now, ShipDate = DateTime.Now }; var product = Context.Products.FirstOrDefault(); var orderDetail = new OrderDetail { ProductNavigation = product, UnitCost = 12.99M, Quantity = 1 }; order.OrderDetails.Add(orderDetail); cust.Orders.Add(order); ICustomerRepo custRepo = new CustomerRepo(Context); custRepo.Add(cust); Context.CustomerId = cust.Id; Assert.NotNull(Context.Customers.FirstOrDefault()); Assert.NotNull(Context.Orders.FirstOrDefault()); Assert.NotNull(Context.OrderDetails.FirstOrDefault()); var orderRepo = new OrderRepo(Context, new OrderDetailRepo(Context)); var record = orderRepo.GetOneWithDetails(1); var foo = "foo"; } }
public void ShouldSetServerSideProperties() { var cat = new Category { CategoryName = "CatName" }; ExecuteInATransaction(RunTheTest); void RunTheTest() { SampleDataInitializer.ClearData(Context); Assert.Equal(0, cat.Id); Assert.Null(cat.TimeStamp); Context.Categories.Add(cat); Assert.True(cat.Id == 0); Assert.Null(cat.TimeStamp); Context.SaveChanges(); Assert.Single(Context.Categories.ToList()); Assert.True(cat.Id > 0); Assert.NotNull(cat.TimeStamp); } }
// 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 initializer) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseDefaultFiles(); app.UseMvc(); app.UseStaticFiles(); initializer.CreateUsers(); }