public void CreateCarAddWorksCorrectlyAndSavesInDb() { var options = new DbContextOptionsBuilder <DealershipDbContext>() .UseInMemoryDatabase(databaseName: "Create_CarAdd") .Options; var db = new DealershipDbContext(options); var service = new CarAddsService(db); var inputModel = this.GetCarAddInputModel(); var engineType = service.GetCarEngineType(inputModel.CarEngineType); var transmission = service.GetCarTransmissionType(inputModel.CarTransmission); var category = service.GetCarCategory(inputModel.CarCategory); var extras = service.CreateCarExtras(inputModel.CarExtras); var car = service.CreateCar(inputModel, engineType, transmission, category, extras); var carAdd = service.CreateCarAdd(inputModel, car.Id, "1"); Assert.True(db.CarAdds.Count() == 1); Assert.True(db.CarAdds.First().CarId == car.Id); Assert.True(db.CarAdds.First().CreatorId == "1"); }
public void CreateCarWorksAndSavesCarInDb() { var options = new DbContextOptionsBuilder <DealershipDbContext>() .UseInMemoryDatabase(databaseName: "Create_Car") .Options; var db = new DealershipDbContext(options); var service = new CarAddsService(db); var inputModel = this.GetCarAddInputModel(); var engineType = service.GetCarEngineType(inputModel.CarEngineType); var transmission = service.GetCarTransmissionType(inputModel.CarTransmission); var category = service.GetCarCategory(inputModel.CarCategory); var extras = service.CreateCarExtras(inputModel.CarExtras); var car = service.CreateCar(inputModel, engineType, transmission, category, extras); Assert.True(db.Cars.Count() == 1); Assert.True(db.CarExtras.Count() == 4); Assert.True(db.Cars.First().Make == inputModel.CarMake); Assert.True((int)db.Cars.First().EngineType == 4); Assert.True(db.Cars.First().EngineType.ToString() == Constants.GasolineAndLpgEngineTypeCorrection); }
public void GetAddsAccordingToCriteriaWorksCorrectly() { var options = new DbContextOptionsBuilder <DealershipDbContext>() .UseInMemoryDatabase(databaseName: "Get_Adds_By_Criteria") .Options; var db = new DealershipDbContext(options); var service = new CarAddsService(db); var inputModel = this.GetCarAddInputModel(); var engineType = service.GetCarEngineType(inputModel.CarEngineType); var transmission = service.GetCarTransmissionType(inputModel.CarTransmission); var category = service.GetCarCategory(inputModel.CarCategory); var extras = service.CreateCarExtras(inputModel.CarExtras); var car = service.CreateCar(inputModel, engineType, transmission, category, extras); var carAdd = service.CreateCarAdd(inputModel, car.Id, "1"); var carSelectModel = new CarSelectInputModel { Category = "Saloon", EndPrice = decimal.MaxValue, EndYear = 2019, EngineType = "Gasoline / LPG", HorsePower = 130, Location = "Nqkude", Make = "Opel", Model = "Vectra", StartingPrice = 4000m, StartingYear = 2000, Transmission = "Manual" }; var getCars = service.GetAddsAccordingToCriteria(carSelectModel); Assert.True(getCars.Count() == 1); }
public void GetMyAddsWorksCorrectly() { var options = new DbContextOptionsBuilder <DealershipDbContext>() .UseInMemoryDatabase(databaseName: "Get_My_Adds") .Options; var db = new DealershipDbContext(options); var userMock = new Mock <DealershipUser>(); userMock.Setup(u => u.Id).Returns("1"); userMock.Setup(u => u.UserName).Returns("Pesho"); var service = new CarAddsService(db); var inputModel = this.GetCarAddInputModel(); var engineType = service.GetCarEngineType(inputModel.CarEngineType); var transmission = service.GetCarTransmissionType(inputModel.CarTransmission); var category = service.GetCarCategory(inputModel.CarCategory); var extras = service.CreateCarExtras(inputModel.CarExtras); var car = service.CreateCar(inputModel, engineType, transmission, category, extras); var carAdd = service.CreateCarAdd(inputModel, car.Id, "1"); userMock.Setup(u => u.CarAdds).Returns(new List <CarAdd> { carAdd }); var fakeUser = userMock.Object; db.Users.Add(fakeUser); db.SaveChanges(); var myAdds = service.GetMyAdds("Pesho"); Assert.True(myAdds.Count() == 1); }