コード例 #1
0
        public void Init()
        {
            _calculator = new Mock <IParkingRateCalaulator>();
            _rate       = new NightRate(_calculator.Object);

            _enterTime = new DateTime(2017, 01, 01, 18, 0, 0);
            _exitTime  = new DateTime(2017, 01, 02, 6, 00, 00);

            _calculator.Setup(calc => calc.CalculateRate(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(100);
        }
コード例 #2
0
        /// <summary>
        /// Acquire correct rate based on business rules
        /// </summary>
        /// <param name="enter">Entry time</param>
        /// <param name="exit"Exit time</param>
        /// <returns>Instance of Rate</returns>
        public Rate GetCorrectRate(DateTime enter, DateTime exit)
        {
            Rate      earlyBird    = new EarlyBirdRate();
            Rate      nightRate    = new NightRate();
            Rate      standardRate = new StandardRate();
            DayOfWeek dow          = enter.DayOfWeek;

            if (enter >= earlyBird.EnterStartTime && enter <= earlyBird.EnterEndTime)
            {
                if (exit >= earlyBird.ExitStartTime && exit <= earlyBird.ExitEndTime)
                {
                    return(earlyBird);
                }
                else
                {
                    return(standardRate);
                }
            }
            else if (enter >= nightRate.EnterStartTime && enter <= nightRate.EnterEndTime)
            {
                if ((dow == DayOfWeek.Saturday) || (dow == DayOfWeek.Sunday))
                {
                    return(standardRate);
                }

                int dayDifference = exit.Day - enter.Day;
                if ((dayDifference == 1) && exit.Hour <= 6)
                {
                    return(nightRate);
                }
                else
                {
                    return(standardRate);
                }
            }
            else
            {
                return(standardRate);
            }
        }
コード例 #3
0
        public virtual IParkingRate CreateParkingRate(RateName rateType)
        {
            IParkingRate parkingRate = null;

            switch (rateType)
            {
            case RateName.Standard:
                parkingRate = new StandardRate("Standard Rate");
                break;

            case RateName.Night:
                parkingRate = new NightRate("Night Rate");
                break;

            case RateName.EarlyBird:
                parkingRate = new EarlyBirdRate("Early Bird Rate");
                break;

            case RateName.Weekend:
                parkingRate = new WeekendRate("Weekend Rate");
                break;
            }
            return(parkingRate);
        }
コード例 #4
0
 public NightRateTests()
 {
     _rate = new NightRate();
 }