public void EmptyConfigThrowsException()
        {
            var mockRateCalculatorFactory = Substitute.For <IRateCalculatorFactory>();
            var mockCalculatorFactory     = Substitute.For <IRateCalculator>();


            var parameters = new ParkingParameters
            {
                Entry = DateTime.Today,
                Exit  = DateTime.Now
            };

            mockRateCalculatorFactory.GetRateCalculator(parameters).Returns(mockCalculatorFactory);
            mockCalculatorFactory.GetAmount(parameters).Returns(10.00m);

            mockCalculatorFactory.GetRateName().Returns("standard");

            var rateService = new RateService(mockRateCalculatorFactory);

            var result = rateService.GetTicket(parameters);

            Assert.Equal(10.00m, result.Result.Amount);

            Assert.Equal("standard", result.Result.RateName);
        }
Beispiel #2
0
        public async Task <Ticket> GetTicket(ParkingParameters parkingParameters)
        {
            var calculator = _rateCalculatorFactory.GetRateCalculator(parkingParameters);

            var ticket = new Ticket
            {
                Amount   = calculator.GetAmount(parkingParameters),
                RateName = calculator.GetRateName()
            };

            return(ticket);
        }
        public async Task <IActionResult> CalculateRate(DateTime entry, DateTime exit)
        {
            if (entry > exit)
            {
                return(BadRequest("Exit date must be before entry date"));
            }

            var parkingParameters = new ParkingParameters
            {
                Entry = entry,
                Exit  = exit
            };

            var ticket = await _rateService.GetTicket(parkingParameters);

            return(Ok(ticket));
        }
        public bool IsValid(ParkingParameters parkingParameters)
        {
            if (parkingParameters.Days > _rateConditions.MaxDays)
            {
                return(false);
            }

            var currentEntryTime = parkingParameters.Entry.TimeOfDay;
            var currentExitTime  = parkingParameters.Exit.TimeOfDay;

            var currentEntryDayOfWeek = parkingParameters.Entry.DayOfWeek;
            var currentExitDayOfWeek  = parkingParameters.Exit.DayOfWeek;

            return(IsBetweenValidRange(currentEntryTime, _rateConditions.EntryTimeRange) &&
                   IsBetweenValidRange(currentExitTime, _rateConditions.ExitTimeRange) &&
                   _rateConditions.EntryDaysRange.Contains((int)currentEntryDayOfWeek) &&
                   _rateConditions.ExitDaysRange.Contains((int)currentExitDayOfWeek));
        }
 public decimal GetAmount(ParkingParameters parameters)
 {
     return((parameters.Days + (parameters.Hours == 24 ? 0 : 1)) * _config.Price);
 }
        public IRateCalculator GetRateCalculator(ParkingParameters parameters)
        {
            var rateCalculator = _rateManagers.FirstOrDefault(condition => condition.Key.IsValid(parameters));

            return(rateCalculator.Value ?? new DefaultRateCalculator(_ratesConfiguration.DefaultRate));
        }
 public bool IsValid(ParkingParameters parkingParameters)
 {
     return(_rates.MaxHours >= parkingParameters.Hours);
 }
 public decimal GetAmount(ParkingParameters parameters)
 {
     return(parameters.Hours * _rate.Price);
 }
Beispiel #9
0
 public decimal GetAmount(ParkingParameters parameters)
 {
     return(_rateConditions.Price);
 }