Example #1
0
        public void Exit_ShouldBeSlipAndFeeSetAndLotNull()
        {
            List <IParkingSpace> parkingSpaces = new List <IParkingSpace>();

            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            List <IParkingFee> parkingFees = new List <IParkingFee>();

            parkingFees.Add(new ParkingFee(0, 2, 5));
            parkingFees.Add(new ParkingFee(2, 10, 10));
            parkingFees.Add(new ParkingFee(10, Double.MaxValue, 15));
            IParkingLot parkingLot = new ParkingLot(parkingSpaces, parkingFees);

            Car sut = new Car("Honda", "Civic");

            sut.Enter(parkingLot);
            sut.Park();
            sut.Unpark();
            sut.GetParkingSlip().SetExitDateTime(DateTime.UtcNow.AddHours(5));
            IParkingFee parkingFee = sut.Exit();

            Assert.IsNull(sut.GetParkingLot());
            Assert.IsNull(sut.GetParkingSpace());
            Assert.That(sut.GetParkingSlip().GetExitDateTime(), Is.GreaterThan(DateTime.MinValue));
            Assert.That(parkingFee.GetCost(), Is.EqualTo(10));
        }
Example #2
0
        /// <summary>
        /// Exit this parkingLot.
        /// </summary>
        public IParkingFee Exit()
        {
            if (this.ParkingLot == null)
            {
                throw new Exception("This car needs to be in a parking lot before it can exit.");
            }

            // Mark the exit time on the existing parking slip
            this.ParkingSlip.SetExitDateTime(DateTime.UtcNow);
            // See how much this car owes based on time in the lot and the lot's fee structure
            IParkingFee parkingFee = CalculateParkingFee();

            this.ParkingLot = null;
            return(parkingFee);
        }
Example #3
0
        public void GetAvailableParkingSpaces_ShouldBeDecrementedAndIncrementedDuringParking()
        {
            List <IParkingSpace> parkingSpaces = new List <IParkingSpace>();

            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            parkingSpaces.Add(new ParkingSpace());
            List <IParkingFee> parkingFees = new List <IParkingFee>();

            parkingFees.Add(new ParkingFee(0, 2, 5));
            parkingFees.Add(new ParkingFee(2, 10, 10));
            parkingFees.Add(new ParkingFee(10, Double.MaxValue, 15));
            IParkingLot sut = new ParkingLot(parkingSpaces, parkingFees);

            Car car = new Car("Honda", "Civic");

            car.Enter(sut);
            car.Park();

            Assert.That(sut.GetAvailableParkingSpaces().Count, Is.EqualTo(2));

            car.Unpark();

            Assert.That(sut.GetAvailableParkingSpaces().Count, Is.EqualTo(3));

            car.Park();

            Assert.That(sut.GetAvailableParkingSpaces().Count, Is.EqualTo(2));

            car.Unpark();

            Assert.That(sut.GetAvailableParkingSpaces().Count, Is.EqualTo(3));

            car.GetParkingSlip().SetExitDateTime(DateTime.UtcNow.AddHours(5));
            IParkingFee parkingFee = car.Exit();

            Assert.That(sut.GetAvailableParkingSpaces().Count, Is.EqualTo(3));
        }
Example #4
0
        /// <summary>
        /// Calculates the parking fee.
        /// </summary>
        /// <returns>The parking fee.</returns>
        private IParkingFee CalculateParkingFee()
        {
            IParkingFee parkingFee = this.ParkingLot.CalculateParkingFee(this.ParkingSlip);

            return(parkingFee);
        }