示例#1
0
        public TaxServiceTests()
        {
            _vehicleRepository = Fixture.Freeze <IVehicleRepository>();
            _tollFeeRepository = Fixture.Freeze <ITollFeeRepository>();

            _vehicleRepository.GetTollFreeVehiclesAsync().Returns(new List <Vehicle>
            {
                Vehicle.Diplomat,
                Vehicle.Emergency,
                Vehicle.Foreign,
                Vehicle.Military,
                Vehicle.Motorbike,
                Vehicle.Bus
            });

            _tollFeeRepository.GetMaximumDailyFeeAsync().Returns(MAXIMUM_DAILY_FEE);
            _tollFeeRepository.GetPassageLeewayInterval().Returns(_passageLeewayInterval);
        }
示例#2
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);
        }