public void CheckIfChangeCarDetailsActuallyChangesTheDetails() { var dbContext = new AutomobileDbContext(); var service = new CarsService(dbContext); var carFromDb = dbContext.CarOffers.FirstOrDefault(); VisualizeCarDetailsViewModel model = new VisualizeCarDetailsViewModel() { Id = carFromDb.Id, Type = "New", Make = "Audi", Model = "Q7", Kilometers = 150, FuelType = "Diesel", HorsePower = 150, EngineSize = 1500, Gearbox = "Automatic", Price = 5000, Doors = "2", Color = "black", Year = 2000, Description = "testt" }; service.ChangeCarDetails(model); var priceAfterChangeCarDetails = carFromDb.Price; Assert.Equal(priceAfterChangeCarDetails, model.Price); }
public void CheckIfChangeScooterDetailsActuallyChangesTheDetails() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); var scooterFromDb = dbContext.ElectricScooterOffers.FirstOrDefault(); VisualizeScooterDetailsViewModel model = new VisualizeScooterDetailsViewModel() { Id = scooterFromDb.Id, Make = "Xiaomi", Model = "Pro", Kilometers = 150, Condition = "Used", MaxSpeedAchievable = 30, MaxWeight = 100, MotorPower = 500, TiresSize = 8.5m, ScooterSize = "paworoawrpo", TravellingDistance = 35, WaterproofLevel = "IP54", Price = 31231, Year = 2000, Battery = "new", Description = "testt" }; service.ChangeScooterDetails(model); var priceAfterChangeScooterDetails = scooterFromDb.Price; Assert.Equal(priceAfterChangeScooterDetails, model.Price); }
public CarsController(ILogger <CarsController> logger, AutomobileDbContext dbContext, ICarsService carsService, UserManager <ApplicationUser> userManager) { _logger = logger; this.dbContext = new AutomobileDbContext(); this.carsService = carsService; _userManager = userManager; }
public void CheckIfScootersForVisualizationByFiltersAreReturningCorrectOffers() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); FiltersInputModel filtersInputModel = new FiltersInputModel() { Condition = Condition.New, MinPrice = 100, Make = "All", Model = "-- All --", MaxPrice = 1000000, MinKilometers = 0, MaxKilometers = 1000000, MinMotorPower = 0, MaxMotorPower = 50000 }; var scootersCollection = service.ScootersForVisualization(filtersInputModel); var scootersAvailableInDb = dbContext.ElectricScooterOffers.Where(x => x.Condition == Condition.New && x.Price >= 100); Assert.Equal(scootersCollection.Count(), scootersAvailableInDb.Count()); }
public void CheckIfGetOnlyUserMotorcyclesByFiltersReturnsTheCorrectMotorcyclesForThatParticularUser() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); FiltersInputModel filtersInputModel = new FiltersInputModel() { Condition = Condition.New, FuelType = FuelType.Petrol, MinPrice = 100, Make = "All", Model = "-- All --", Gearbox = 0, MaxPrice = 1000000, MinKilometers = 0, MaxKilometers = 1000000, MinYear = 1900, MaxYear = DateTime.Now.Year, }; var motorcyclesCollection = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebb-baf2-667f245a3582", filtersInputModel); var motorcyclesAvailableInDb = dbContext.MotorcycleOffers.Where(x => x.Condition == Condition.New && x.FuelType == FuelType.Petrol && x.Price >= 100 && x.UserId == "e4bf2992-cc46-4ebb-baf2-667f245a3582"); Assert.Equal(motorcyclesCollection.Count(), motorcyclesAvailableInDb.Count()); }
public void CheckIfGetOnlyUserScootersByFiltersReturnsTheCorrectScootersForThatParticularUser() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); FiltersInputModel filtersInputModel = new FiltersInputModel() { Condition = Condition.New, MinPrice = 100, Make = "All", Model = "-- All --", MaxPrice = 1000000, MinKilometers = 0, MaxKilometers = 1000000, MinMotorPower = 0, MaxMotorPower = 5000 }; var scootersCollection = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", filtersInputModel); var scootersAvailableInDb = dbContext.ElectricScooterOffers.Where(x => x.Condition == Condition.New && x.Price >= 100 && x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d"); Assert.Equal(scootersCollection.Count(), scootersAvailableInDb.Count()); }
public void CheckIfMotorcyclesForVisualizationBySortingTypeAreSortedCorrectly() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var motorcyclesCollection = service.MotorcyclesForVisualization("UploadDate"); var motorcyclesAvailableInDb = dbContext.MotorcycleOffers.OrderByDescending(x => x.CreatedOn).ToList(); Assert.Equal(motorcyclesCollection.First().Id, motorcyclesAvailableInDb.First().Id); motorcyclesCollection = service.MotorcyclesForVisualization("LowestPrice"); motorcyclesAvailableInDb = dbContext.MotorcycleOffers.OrderBy(x => x.Price).ToList(); Assert.Equal(motorcyclesCollection.First().Id, motorcyclesAvailableInDb.First().Id); motorcyclesCollection = service.MotorcyclesForVisualization("HighestPrice"); motorcyclesAvailableInDb = dbContext.MotorcycleOffers.OrderByDescending(x => x.Price).ToList(); Assert.Equal(motorcyclesCollection.First().Id, motorcyclesAvailableInDb.First().Id); motorcyclesCollection = service.MotorcyclesForVisualization("OldestYear"); motorcyclesAvailableInDb = dbContext.MotorcycleOffers.OrderBy(x => x.Year).ToList(); Assert.Equal(motorcyclesCollection.First().Id, motorcyclesAvailableInDb.First().Id); motorcyclesCollection = service.MotorcyclesForVisualization("NewestYear"); motorcyclesAvailableInDb = dbContext.MotorcycleOffers.OrderByDescending(x => x.Year).ToList(); Assert.Equal(motorcyclesCollection.First().Id, motorcyclesAvailableInDb.First().Id); }
public void CheckIfMotorcyclesForVisualizationByFiltersAreReturningCorrectOffers() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); FiltersInputModel filtersInputModel = new FiltersInputModel() { Condition = Condition.New, FuelType = FuelType.Petrol, MinPrice = 100, Make = "All", Model = "-- All --", Gearbox = 0, SteeringWheelSide = 0, MaxPrice = 1000000, MinKilometers = 0, MaxKilometers = 1000000, MinYear = 1900, MaxYear = DateTime.Now.Year, }; var motorcyclesCollection = service.MotorcyclesForVisualization(filtersInputModel); var motorcyclesAvailableInDb = dbContext.MotorcycleOffers.Where(x => x.Condition == Condition.New && x.FuelType == FuelType.Petrol && x.Price >= 100); Assert.Equal(motorcyclesCollection.Count(), motorcyclesAvailableInDb.Count()); }
public void CheckIfAddMotorcycleAddsTheMotorcycle() { var dbContext = new AutomobileDbContext(); var service = new OfferService(dbContext); IFormFile file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, "Data", "dummy.txt"); service.AddMotorcycle(new AddMotorcycleViewModel() { Title = "Test", Make = "BMW", Model = "HB4", Year = 2003, Price = 220, Condition = (Condition)Enum.Parse(typeof(Condition), "New"), Color = "black", FuelType = (FuelType)Enum.Parse(typeof(FuelType), "Diesel"), HorsePower = 50, CubicCentimeters = 650, Gearbox = (Gearbox)Enum.Parse(typeof(Gearbox), "Automatic"), Kilometers = 15000, Description = "asasrsa", ContactNumber = "03210320232", MainImageFile = file }, "e4bf2992-cc46-4ebb-baf2-667f245a3582"); var motorcycleOffersContainMotorcycle = dbContext.MotorcycleOffers.Any(x => x.Title == "Test"); Assert.True(motorcycleOffersContainMotorcycle); var mockMotorcycle = dbContext.MotorcycleOffers.FirstOrDefault(x => x.Title == "Test"); dbContext.MotorcycleOffers.Remove(mockMotorcycle); dbContext.SaveChanges(); }
public void CheckIfChangeMotorcycleDetailsActuallyChangesTheDetails() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var motorcycleFromDb = dbContext.MotorcycleOffers.FirstOrDefault(); VisualizeMotorcycleDetailsViewModel model = new VisualizeMotorcycleDetailsViewModel() { Id = motorcycleFromDb.Id, Type = "New", Make = "BMW", Model = "HB2", Kilometers = 150, FuelType = "Diesel", Gearbox = "Manual", HorsePower = 32, Price = 5000, CubicCentimeters = 650, Color = "black", Year = 2000, Description = "testt" }; service.ChangeMotorcycleDetails(model); var priceAfterChangeMotorcycleDetails = motorcycleFromDb.Price; Assert.Equal(priceAfterChangeMotorcycleDetails, model.Price); }
public IndexModel( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, AutomobileDbContext dbContext) { _userManager = userManager; _signInManager = signInManager; this.dbContext = dbContext; }
public void CheckIfGetMotorcycleByIdReturnsCorrectMotorcycle() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var motorcycleFromDb = dbContext.MotorcycleOffers.FirstOrDefault(); var motorcycleFromService = service.GetMotorcycleById(motorcycleFromDb.Id); Assert.Equal(motorcycleFromDb.Id, motorcycleFromService.Id); }
public void CheckIfScootersForVisualizationAreEqualToScootersInDb() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); var scootersCollection = service.ScootersForVisualization(); var scootersAvailableInDb = dbContext.ElectricScooterOffers.ToList(); Assert.True(scootersCollection.Count == scootersAvailableInDb.Count); }
public void CheckIfGetScooterByIdReturnsCorrectScooter() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); var scooterFromDb = dbContext.ElectricScooterOffers.FirstOrDefault(); var scooterFromService = service.GetScooterById(scooterFromDb.Id); Assert.Equal(scooterFromDb.Id, scooterFromService.Id); }
public void CheckIfMotorcyclesForVisualizationAreEqualToMotorcyclesInDb() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var motorcyclesCollection = service.MotorcyclesForVisualization(); var motorcyclesAvailableInDb = dbContext.MotorcycleOffers.ToList(); Assert.True(motorcyclesCollection.Count == motorcyclesAvailableInDb.Count); }
public void CheckIfCarsForVisualizationAreEqualToCarsInDb() { var dbContext = new AutomobileDbContext(); var service = new CarsService(dbContext); var carsCollection = service.CarsForVisualization(); var carsAvailableInDb = dbContext.CarOffers.ToList(); Assert.True(carsCollection.Count == carsAvailableInDb.Count); }
public void CheckIfGetCarByIdReturnsCorrectCar() { var dbContext = new AutomobileDbContext(); var service = new CarsService(dbContext); var carFromDb = dbContext.CarOffers.FirstOrDefault(); var carFromService = service.GetCarById(carFromDb.Id); Assert.Equal(carFromDb.Id, carFromService.Id); }
public void CheckIfGetOnlyUserMotorcyclesReturnsTheMotorcyclesForThatParticularUserOnly() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var serviceOnlyUserMotorcycles = service.GetOnlyUserMotorcycles("e4bf2992cc46-4ebbbaf2-667f245a3582"); var dbOnlyUserMotorcycles = dbContext.MotorcycleOffers.Where(x => x.UserId == "e4bf2992cc46-4ebb-baf2-667f245a3582"); Assert.Equal(dbOnlyUserMotorcycles.Count(), serviceOnlyUserMotorcycles.Count()); }
public void CheckIfGetOnlyUserScootersReturnsTheScootersForThatParticularUserOnly() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); var serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d"); var dbOnlyUserScooters = dbContext.ElectricScooterOffers.Where(x => x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d"); Assert.Equal(dbOnlyUserScooters.Count(), serviceOnlyUserScooters.Count()); }
public void CheckIfGetOnlyUserScootersBySortingReturnsTheCorrectScootersForThatParticularUser() { var dbContext = new AutomobileDbContext(); var service = new ElectricScootersService(dbContext); var serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "UploadDate"); var dbOnlyUserScooters = dbContext.ElectricScooterOffers.Where(x => x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d").OrderByDescending(x => x.CreatedOn).ToList(); if (serviceOnlyUserScooters.Count == 0 && dbOnlyUserScooters.Count == 0) { Assert.Equal(dbOnlyUserScooters.Count(), serviceOnlyUserScooters.Count()); return; } Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title); serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "LowestPrice"); dbOnlyUserScooters = dbOnlyUserScooters .OrderBy(x => x.Price).ToList(); Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title); serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "HighestPrice"); dbOnlyUserScooters = dbOnlyUserScooters .OrderByDescending(x => x.Price).ToList(); Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title); serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "OldestYear"); dbOnlyUserScooters = dbOnlyUserScooters .OrderBy(x => x.Year).ToList(); Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title); serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "NewestYear"); dbOnlyUserScooters = dbOnlyUserScooters .OrderByDescending(x => x.Year).ToList(); Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title); Assert.Equal(dbOnlyUserScooters.Count(), serviceOnlyUserScooters.Count()); }
public void CheckIfGetOnlyUserMotorcyclesBySortingReturnsTheCorrectMotorcyclesForThatParticularUser() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var serviceOnlyUserMotorcycles = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebbbaf2-667f245a3582", "UploadDate"); var dbOnlyUserMotorcycles = dbContext.MotorcycleOffers.Where(x => x.UserId == "e4bf2992cc46-4ebb-baf2-667f245a3582").OrderByDescending(x => x.CreatedOn).ToList(); if (serviceOnlyUserMotorcycles.Count == 0 && dbOnlyUserMotorcycles.Count == 0) { Assert.Equal(dbOnlyUserMotorcycles.Count(), serviceOnlyUserMotorcycles.Count()); return; } Assert.Equal(serviceOnlyUserMotorcycles.FirstOrDefault().Title, dbOnlyUserMotorcycles.FirstOrDefault().Title); serviceOnlyUserMotorcycles = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebbbaf2-667f245a3582", "LowestPrice"); dbOnlyUserMotorcycles = dbOnlyUserMotorcycles .OrderBy(x => x.Price).ToList(); Assert.Equal(serviceOnlyUserMotorcycles.FirstOrDefault().Title, dbOnlyUserMotorcycles.FirstOrDefault().Title); serviceOnlyUserMotorcycles = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebbbaf2-667f245a3582", "HighestPrice"); dbOnlyUserMotorcycles = dbOnlyUserMotorcycles .OrderByDescending(x => x.Price).ToList(); Assert.Equal(serviceOnlyUserMotorcycles.FirstOrDefault().Title, dbOnlyUserMotorcycles.FirstOrDefault().Title); serviceOnlyUserMotorcycles = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebbbaf2-667f245a3582", "OldestYear"); dbOnlyUserMotorcycles = dbOnlyUserMotorcycles .OrderBy(x => x.Year).ToList(); Assert.Equal(serviceOnlyUserMotorcycles.FirstOrDefault().Title, dbOnlyUserMotorcycles.FirstOrDefault().Title); serviceOnlyUserMotorcycles = service.GetOnlyUserMotorcycles("e4bf2992-cc46-4ebbbaf2-667f245a3582", "NewestYear"); dbOnlyUserMotorcycles = dbOnlyUserMotorcycles .OrderByDescending(x => x.Year).ToList(); Assert.Equal(serviceOnlyUserMotorcycles.FirstOrDefault().Title, dbOnlyUserMotorcycles.FirstOrDefault().Title); Assert.Equal(dbOnlyUserMotorcycles.Count(), serviceOnlyUserMotorcycles.Count()); }
public RegisterModel( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, AutomobileDbContext dbContext) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; this.dbContext = dbContext; }
public void CheckIfDeleteMotorcycleOfferRemovesTheOfferFromTheDatabase() { var dbContext = new AutomobileDbContext(); var service = new MotorcyclesService(dbContext); var dbOffer = dbContext.MotorcycleOffers.FirstOrDefault(); var offerImages = dbContext.OfferImages.Where(x => x.MotorcycleOfferId == dbOffer.Id); var getMotorcycleOfferById = service.GetMotorcycleOfferById(dbOffer.Id); service.DeleteMotorcycleOffer(getMotorcycleOfferById); Assert.True(dbContext.MotorcycleOffers.Any(x => x.Id == dbOffer.Id) == false); //Add removed motorcycle and images so that db remains the same. Set Offer Id = 0 to not override identity for Id in database. getMotorcycleOfferById.Id = 0; dbContext.MotorcycleOffers.Add(getMotorcycleOfferById); dbContext.OfferImages.AddRange(offerImages); dbContext.SaveChanges(); }
public void CheckIfAddElectricScooterAddsTheScooter() { var dbContext = new AutomobileDbContext(); var service = new OfferService(dbContext); IFormFile file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, "Data", "dummy.txt"); service.AddElectricScooter(new AddElectricScooterViewModel() { Title = "Test", Make = "Xiaomi", Model = "365", Year = 2003, Price = 220, Condition = (Condition)Enum.Parse(typeof(Condition), "New"), WaterproofLevel = "test", MaxSpeedAchievable = 25, MotorPower = 250, ScooterSize = "2413", TiresSize = 8.5m, TravellingDistance = 205, Battery = "test", Kilometers = 15000, Description = "asasrsa", ContactNumber = "03210320232", MainImageFile = file }, "e4bf2992-cc46-4ebb-baf2-667f245a3582"); var scooterOffersContainScooter = dbContext.ElectricScooterOffers.Any(x => x.Title == "Test"); Assert.True(scooterOffersContainScooter); var mockScooter = dbContext.ElectricScooterOffers.FirstOrDefault(x => x.Title == "Test"); dbContext.ElectricScooterOffers.Remove(mockScooter); dbContext.SaveChanges(); }
public void CheckIfAddCarAddsTheCar() { var dbContext = new AutomobileDbContext(); var service = new OfferService(dbContext); IFormFile file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, "Data", "dummy.txt"); service.AddCar(new AddCarViewModel() { Title = "Test", Make = "Audi", Model = "A3", Year = 2003, Price = 220, Condition = (Condition)Enum.Parse(typeof(Condition), "New"), Color = "black", SteeringWheelSide = 0, FuelType = (FuelType)Enum.Parse(typeof(FuelType), "Diesel"), HorsePower = 150, EngineSize = 1060, Gearbox = (Gearbox)Enum.Parse(typeof(Gearbox), "Automatic"), Doors = "2", Kilometers = 15000, ContactNumber = "03210320232", MainImageFile = file }, "e4bf2992-cc46-4ebb-baf2-667f245a3582"); var carOffersContainCar = dbContext.CarOffers.Any(x => x.Title == "Test"); Assert.True(carOffersContainCar); var mockCar = dbContext.CarOffers.FirstOrDefault(x => x.Title == "Test"); dbContext.CarOffers.Remove(mockCar); dbContext.SaveChanges(); }
public OfferService(AutomobileDbContext dbContext) { this.dbContext = dbContext; }
public OfferController(ILogger <OfferController> logger, AutomobileDbContext dbContext, IOfferService offerService) { _logger = logger; this.dbContext = new AutomobileDbContext(); this.offerService = offerService; }
public FiltersInputModel() { dbContext = new AutomobileDbContext(); }
public AddMotorcycleViewModel(AutomobileDbContext dbContext) { this.dbContext = dbContext; }
public MakeController(AutomobileDbContext context, IMapper mapper) { this.context = context; this.mapper = mapper; }