コード例 #1
0
        public void Mapping_SpecialRate_ToEntryResponse_IsCorrect()
        {
            //arrange
            var specialRate = new SpecialRate {
                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.FromSpecialRate(specialRate, entryRequest);

            //assert
            Assert.AreEqual(specialRate.TotalPrice, result.Amount, "Amount not match");
            Assert.AreEqual(specialRate.Type, result.RateType, "Rate Type not match");
            Assert.AreEqual(specialRate.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");
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        private static IEntryResponse CalculateWeekendParkingFee(IEntryRequest request)
        {
            var weekendRate = JsonConvert.DeserializeObject <List <SpecialRate> >(Resources.specialrates).Single(r => r.Weekend);

            return(EntryResponse.FromSpecialRate(weekendRate, request));
        }