public void Mapping_StandardRate_ToEntryResponse_IsCorrect() { //arrange var standardRate = new StandardRate { TotalPrice = 10, Name = "Test Rate Name", Type = "Test Rate Type" }; var entryRequest = BuildEntryRequest(DateTime.Now.AddHours(-1).ToString(), DateTime.Now.ToString()); //act var result = EntryResponse.FromStandardRate(standardRate, entryRequest); //assert Assert.AreEqual(standardRate.TotalPrice, result.Amount, "Amount not match"); Assert.AreEqual(standardRate.Type, result.RateType, "Rate Type not match"); Assert.AreEqual(standardRate.Name, result.RateName, "Rate Name not match"); Assert.AreEqual(entryRequest.RegistrationNo, result.RegistrationNo, "Registration No not match"); Assert.AreEqual(entryRequest.EntryTime, result.EntryTime, "Entry Time not match"); Assert.AreEqual(entryRequest.ExitTime, result.ExitTime, "Exit Time not match"); }
private static IEntryResponse CalculateWeekdayParkingFee(IEntryRequest request) { var daysDifference = GetDaysDifference(request.EntryTimeLocal, request.ExitTimeLocal); if (daysDifference < 2) { var specialRates = JsonConvert.DeserializeObject <List <SpecialRate> >(Resources.specialrates).Where(r => !r.Weekend); var applicableSpecialRate = specialRates.SingleOrDefault(r => request.EntryTimeLocal.TimeOfDay >= TimeSpan.Parse(r.EntryPeriodStart) && request.EntryTimeLocal.TimeOfDay <= TimeSpan.Parse(r.EntryPeriodEnd) && request.ExitTimeLocal.TimeOfDay >= TimeSpan.Parse(r.ExitPeriodStart) && request.ExitTimeLocal.TimeOfDay <= TimeSpan.Parse(r.ExitPeriodEnd)); if (applicableSpecialRate != null) { return(EntryResponse.FromSpecialRate(applicableSpecialRate, request)); } } // Standard Rates StandardRate applicableStandardRate; var standardRates = JsonConvert.DeserializeObject <List <StandardRate> >(Resources.standardrates); if (daysDifference == 0) { applicableStandardRate = standardRates.SingleOrDefault(r => request.ExitTimeLocal.TimeOfDay.Subtract(request.EntryTimeLocal.TimeOfDay).TotalMinutes > r.MinimumHours * 60 && request.ExitTimeLocal.TimeOfDay.Subtract(request.EntryTimeLocal.TimeOfDay).TotalMinutes <= r.MaximumHours * 60); } else { applicableStandardRate = standardRates.OrderByDescending(r => r.MaximumHours).FirstOrDefault(); applicableStandardRate.TotalPrice = applicableStandardRate.TotalPrice * daysDifference; } return(EntryResponse.FromStandardRate(applicableStandardRate, request)); }