public void CancelRezervationTest() { using (var context = new CarRentalDbContext(this.dbContextOptions)) { var dbRezervation = context.Rezervations.First(x => !x.IsPickedUp && !x.IsReturned); var clientAccountService = new ClientAccountService(context); var rezervationService = new RezervationService(context, clientAccountService); var cancelationFeeRate = 2.00m; var isCancelled = rezervationService.CancelRezervation(dbRezervation.RezervationId, cancelationFeeRate); Assert.IsTrue(isCancelled); var carType = CarTypes.GetCarType((CarTypeEnum)dbRezervation.CarType); // Test the actual calculations in the car type class. var cancellationFee = carType.CancellationFee * cancelationFeeRate; dbRezervation = context.Rezervations.Single(x => x.RezervationId == dbRezervation.RezervationId); Assert.IsTrue(dbRezervation.IsCancelled); Assert.AreEqual(dbRezervation.CancellationFee, cancellationFee); Assert.AreEqual(dbRezervation.CancelationFeeRate, cancelationFeeRate); } }
public void CreateRezervationTest() { var createRezervationParameters = new RezervationCreationParameters { PickUpDate = DateTime.Today.AddDays(1), // set to Today for simplicity. ReturnDate = DateTime.Today.AddDays(5), CarPlateNumber = "CA1234AC", CarType = CarTypeEnum.Family, ClientAccount = new ClientAccountCreationParams { Email = "*****@*****.**", FullName = "Client_Rez_1", Phone = "+12345", }, }; using (var context = new CarRentalDbContext(this.dbContextOptions)) { var clientAccountService = new ClientAccountService(context); var rezervationService = new RezervationService(context, clientAccountService); var rezervationModel = rezervationService.CreateBooking(createRezervationParameters); // Sanity check Assert.IsTrue(rezervationModel.RezervationId > 0); Assert.AreEqual(rezervationModel.PickUpDate, createRezervationParameters.PickUpDate); Assert.AreEqual(rezervationModel.ReturnDate, createRezervationParameters.ReturnDate); Assert.AreEqual(rezervationModel.CarPlateNumber, createRezervationParameters.CarPlateNumber); Assert.AreEqual(rezervationModel.CarType, createRezervationParameters.CarType); Assert.AreEqual(rezervationModel.IsCancelled, false); Assert.AreEqual(rezervationModel.IsPickedUp, false); Assert.AreEqual(rezervationModel.IsReturned, false); // Fee calculation. var carType = CarTypes.GetCarType(createRezervationParameters.CarType); // Test the actual calculations in the car type class. var rentalFee = carType.RentalRateFee * (decimal)(createRezervationParameters.ReturnDate - createRezervationParameters.PickUpDate).TotalHours; var depositFee = rentalFee * (carType.DepositFeePercentage / 100); Assert.AreEqual(rezervationModel.RentaltFee, rentalFee); Assert.AreEqual(rezervationModel.DepositFee, depositFee); Assert.IsNull(rezervationModel.CancelationFeeRate); var createRezervationParametersExistingClient = new RezervationCreationParameters { PickUpDate = DateTime.Today.AddDays(1), // set to Today for simplicity. ReturnDate = DateTime.Today.AddDays(5), CarPlateNumber = "CA1234AC", CarType = CarTypeEnum.Family, ClientId = context.ClientAccounts.First().ClientId, }; rezervationModel = rezervationService.CreateBooking(createRezervationParametersExistingClient); Assert.IsTrue(rezervationModel.RezervationId > 0); try { var createRezervationParametersNoClient = new RezervationCreationParameters { PickUpDate = DateTime.Today.AddDays(1), // set to Today for simplicity. ReturnDate = DateTime.Today.AddDays(5), CarPlateNumber = "CA1234AC", CarType = CarTypeEnum.Family, }; rezervationModel = rezervationService.CreateBooking(createRezervationParametersNoClient); Assert.Fail(); } catch (InvalidParameterException) { } catch { Assert.Fail(); } } }