public async System.Threading.Tasks.Task Fail_GetAllAsync() { // Arrange var options = new DbContextOptionsBuilder <CarSalesDbContext>().UseInMemoryDatabase(databaseName: "CarSales_Mini").Options; // Insert seed data into the database using one instance of the context using (var context = new CarSalesDbContext(options)) { context.Vehicle.RemoveRange(await context.Vehicle.ToListAsync()); context.SaveChanges(); context.Vehicle.Add(GetCar("Toyota")); context.Vehicle.Add(GetCar("BMW")); context.Vehicle.Add(GetCar("Mec")); context.Vehicle.Add(GetBike("Bike1")); context.Vehicle.Add(GetBike("Bike2")); context.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new CarSalesDbContext(options)) { // Set var appSettings = Options.Create(new AppSettings { BikeController = "BikeService", CarController = "BikeService" }); List <IVehicleService> _vehicleService = new List <IVehicleService>(); IVehicleService carService = new CarService(context); IVehicleService bikeService = new BikeService(context); _vehicleService.Add(carService); _vehicleService.Add(bikeService); CarController carController = new CarController(_vehicleService, appSettings); // Act var result = await carController.GetCarListAsync(); var viewResult = Assert.IsType <ActionResult <List <Vehicle> > >(result); var model = Assert.IsAssignableFrom <List <Vehicle> >(viewResult.Value); // Assert Assert.Equal(3, model.Count()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CarSalesDbContext carSalesDbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } 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(); } carSalesDbContext.Database.EnsureCreated(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseReactDevelopmentServer(npmScript: "start"); } }); }
public MakesController(CarSalesDbContext context) { _context = context; }
public VehicleService(CarSalesDbContext dbContext) { _dbContext = dbContext; }
public BikeService(CarSalesDbContext dbContext) { _dbContext = dbContext; }
public VehicleTypesController(CarSalesDbContext context) { _context = context; }
public VehicleController(CarSalesDbContext dbContext) { this.dbContext = dbContext; }
public BodyTypesController(CarSalesDbContext context) { _context = context; }
public ModelsController(CarSalesDbContext context) { _context = context; }