public double GetPriceForRental(string rentalNumber, double dailyBaseCost, double milageKmBaseCost )
        {
            var rentalInfo = _rentalsRepository.GetRental(rentalNumber);
            if (rentalInfo.Status != RentalInfo.ERentStatus.Returned)
            {
                // Can not calculate price when there is no return date
                return 0.0;
            }

            var vehicleType = _vehicleTypesFactory.GetVehicleType(rentalInfo.VehicleTypeName);

            DateTime returnDate = rentalInfo.ReturnDate.GetValueOrDefault();
            TimeSpan rentalTime = (returnDate - rentalInfo.RentalDate);
            int numberOfRentalDays = RoundUpTimeSpanToClosestWholeDay(rentalTime);
            double numberOfMilageKm = rentalInfo.NewMileageKm.GetValueOrDefault() - rentalInfo.OriginalMileageKm;

            var costParameters = new CostParameters()
            {
                DailyBaseCost = dailyBaseCost,
                MilageKmBaseCost = milageKmBaseCost,
                NumberOfMilageKm = numberOfMilageKm,
                NumberOfRentalDays = numberOfRentalDays
            };

            double rentalToPay = vehicleType.GetRentalCost(costParameters);

            return rentalToPay;
        }
        public void Test_rental_cost_per_type()
        {
            var factory = new Factory();
            var costPar = new CostParameters()
            {
                DailyBaseCost = 500,
                MilageKmBaseCost = 5,
                NumberOfMilageKm = 100,
                NumberOfRentalDays = 3
            };

            Assert.IsTrue(factory.GetVehicleType("Hummer").GetRentalCost(costPar) == 21000.0);
            Assert.IsTrue(factory.GetVehicleType("MonsterTruck").GetRentalCost(costPar) == 31500.0);
            Assert.IsTrue(factory.GetVehicleType("Småbil").GetRentalCost(costPar) == 1500.0);
            Assert.IsTrue(factory.GetVehicleType("Kombi").GetRentalCost(costPar) == 2450.0);
            Assert.IsTrue(factory.GetVehicleType("Lastbil").GetRentalCost(costPar) == 3000.0);
        }
Пример #3
0
 public double GetRentalCost(CostParameters costPar)
 {
     double price = costPar.DailyBaseCost * costPar.NumberOfRentalDays;
     return price;
 }
Пример #4
0
 public double GetRentalCost(CostParameters costPar)
 {
     double price = costPar.DailyBaseCost * costPar.NumberOfRentalDays * 1.3 + costPar.MilageKmBaseCost * costPar.NumberOfMilageKm;
     return price;
 }