public void ChangeLocationShould_SuccessfullyChangeLocation() { var options = new DbContextOptionsBuilder <CarRentalDbContext>() .UseInMemoryDatabase(databaseName: "CarRental_Database_CarChangeLocation") .Options; var dbContext = new CarRentalDbContext(options); var carsService = new CarsService(dbContext, this.cloudinary, this.mapper); var car = new Car { Id = 1, Model = CarModelTestOne, Description = CarModelDescriptionOne, GearType = Models.Enums.GearType.Automatic, LocationId = locationIdOne, PricePerDay = CarPricePerDayTwo, Image = CarImageTest, Year = DateTime.UtcNow.Year }; carsService.AddCar(car); var expectedLocation = locationIdOne; var actualResultLocation = dbContext.Cars.FirstOrDefault().LocationId; Assert.Equal(expectedLocation, actualResultLocation); carsService.ChangeLocation(car.Id, locationIdTwo); var updatedCar = carsService.FindCar(car.Id).GetAwaiter().GetResult(); Assert.Equal(locationIdTwo, updatedCar.LocationId); }
public void ChangeLocationShould_ReturnFalseIfInvalidCarId() { var options = new DbContextOptionsBuilder <CarRentalDbContext>() .UseInMemoryDatabase(databaseName: "CarRental_Database_CarChangeLocation_InvalidCarId") .Options; var dbContext = new CarRentalDbContext(options); var carsService = new CarsService(dbContext, this.cloudinary, this.mapper); var result = carsService.ChangeLocation(1, locationIdOne).GetAwaiter().GetResult(); Assert.False(result); }