示例#1
0
        private async Task <decimal> GetTotalFeeForDay(List <DateTime> passageDates)
        {
            passageDates.Sort((a, b) => a.CompareTo(b));
            var leewayInterval = await _tollFeeRepository.GetPassageLeewayInterval();

            var intervalStart      = passageDates.First();
            var intervalHighestFee = await _tollFeeRepository.GetPassageFeeByTimeAsync(intervalStart);

            decimal totalFee = 0;

            foreach (var passageDate in passageDates)
            {
                var passageFee = await _tollFeeRepository.GetPassageFeeByTimeAsync(passageDate);

                var diff = passageDate - intervalStart;

                if (diff <= leewayInterval)
                {
                    if (totalFee > 0)
                    {
                        totalFee -= intervalHighestFee;
                    }
                    if (passageFee >= intervalHighestFee)
                    {
                        intervalHighestFee = passageFee;
                    }
                    totalFee += intervalHighestFee;
                }
                else
                {
                    totalFee          += passageFee;
                    intervalStart      = passageDate;
                    intervalHighestFee = passageFee;
                }
            }

            var maximumDailyFee = await _tollFeeRepository.GetMaximumDailyFeeAsync();

            if (totalFee > maximumDailyFee)
            {
                totalFee = maximumDailyFee;
            }
            return(totalFee);
        }
示例#2
0
        public void ForGetTotalFee_When2PassagesMoreThanAnHourApart_ReturnFeeForBothPassages()
        {
            var vehicleType  = Vehicle.Car;
            var passageFee   = MAXIMUM_DAILY_FEE / 8;
            var passage1     = new DateTime(1, 1, 1, 12, 50, 0);
            var passage2     = new DateTime(1, 1, 1, 14, 50, 0);
            var passageDates = new List <DateTime>
            {
                passage1,
                passage2
            };

            _tollFeeRepository.GetPassageFeeByTimeAsync(Arg.Is(passage1)).Returns(passageFee);
            _tollFeeRepository.GetPassageFeeByTimeAsync(Arg.Is(passage2)).Returns(passageFee);
            _tollFeeRepository.IsTollFreeDateAsync(Arg.Any <DateTime>()).Returns(false);

            var response = SUT.GetTotalFee(vehicleType, passageDates);

            Assert.Equal(passageFee * 2, response);
        }