public void GetCheapestSpecialRate_NonSpecialRequest_ReturnNoApplicableRates() { // Arrange var entered = new DateTime(2020, 8, 10, 8, 0, 0); var exited = new DateTime(2020, 8, 10, 17, 0, 0); using (var context = new RatesDbContext(options)) { context.SpecialRates.Add(new SpecialRate { Name = "Weekend Rate", RateType = RateType.Flat, Rate = 10.00, EnterFrom = new DateTime(2000, 1, 1, 0, 0, 0), EnterTo = new DateTime(2000, 1, 2, 23, 59, 59), ExitFrom = new DateTime(2000, 1, 1, 0, 0, 0), ExitTo = new DateTime(2000, 1, 2, 23, 59, 59), ApplicableDaysOfWeek = new List <DayOfWeek> { DayOfWeek.Saturday, DayOfWeek.Sunday } }); context.SaveChanges(); var _mockedParkingRateService = new ParkingRateService(context, _mapper, _mockedLogger.Object); // Act var response = _mockedParkingRateService.GetCheapestSpecialRate(entered, exited); // Assert Assert.Null(response); } }
public void GetStandardRate_2HrDuration_ReturnStandardRate() { // Arrange var entered = new DateTime(2020, 8, 8, 8, 0, 0); var exited = new DateTime(2020, 8, 8, 10, 0, 0); using (var context = new RatesDbContext(options)) { context.StandardRates.Add(new StandardRate { Name = "Standard Rate", RateType = RateType.Hourly, Rate = 5.00, MaximumRate = 20.00 }); context.SaveChanges(); var _mockedParkingRateService = new ParkingRateService(context, _mapper, _mockedLogger.Object); // Act var response = _mockedParkingRateService.GetStandardRate(entered, exited); // Assert Assert.NotNull(response); Assert.IsType <GetParkingRateResponse>(response); Assert.Equal(10.00, response.Total); } }
public void When_CalculateParkingFee_Called_ForEntryTime_Returns_CorrectRate(string entryTime, string exitTime, decimal expectedFee) { //arrange var entryRequest = BuildEntryRequest(entryTime, exitTime); //act var result = ParkingRateService.CalculateParkingFee(entryRequest); //assert Assert.AreEqual(expectedFee, result.Amount, "The Fee is not as expected. Incorrect Rate Applied."); }
public void GetStandardRate_NoContextDbData_ThrowsNullException() { // Arrange var entered = new DateTime(2020, 8, 8, 8, 0, 0); var exited = new DateTime(2020, 8, 8, 10, 0, 0); using (var context = new RatesDbContext(options)) { var _mockedParkingRateService = new ParkingRateService(context, _mapper, _mockedLogger.Object); // Act & Assert Assert.Throws <NullReferenceException>(() => _mockedParkingRateService.GetStandardRate(entered, exited)); } }
public ActionResult <IEntryResponse> Post(EntryRequest request) { var entryResponse = ParkingRateService.CalculateParkingFee(request); return(Ok(entryResponse)); }