public RentalReceipt RentVehicle(RentalRequest rentalRequest)
        {
            var vehicleType = _vehicleTypesFactory.GetVehicleType(rentalRequest.VehicleTypeName);

            var receiptFromArgCheck = RentItem_CheckArguments(rentalRequest, vehicleType);
            if (receiptFromArgCheck.Status == ERentalRequestStatus.NotOk)
            {
                return receiptFromArgCheck;
            }

            var rentalInfo = _rentalsRepository.AddNewRental(vehicleType.Name, rentalRequest.RegNo, rentalRequest.RentDateTime, rentalRequest.CurrentMilageKm, rentalRequest.CustomerInfo);
            return new RentalReceipt() {RentalNumber = rentalInfo.RentalNumber, Status = ERentalRequestStatus.Ok, Message = string.Format("A rental for {0} has been registred.", vehicleType)};
        }
        public RentalReceipt MakeRentalRequest(string vehicleTypeName, string regNo, DateTime rentalDay, string personnummer, double currentMilage, IRentalService rentalService)
        {
            // Rental request data
            string vehicleTypeToRent = vehicleTypeName;

            var rentalRequest = new RentalRequest()
            {
                RentDateTime = rentalDay,
                CurrentMilageKm = currentMilage,
                CustomerInfo = new CustomerInfo() { PersonNummer = personnummer },
                VehicleTypeName = vehicleTypeToRent,
                RegNo = regNo
            };
            var rentalReceipt = rentalService.RentVehicle(rentalRequest);
            return rentalReceipt;
        }
        public void Test_rent_with_invalid_vehicle_type()
        {
            // Rental request data
            const double currentMilage = 10001;
            var rentalDay = new DateTime(2015, 10, 14);
            const string vehicleTypeToRent = "non existing type";

            // Make a rental request
            var rentalRequest = new RentalRequest()
            {
                RentDateTime = rentalDay,
                CurrentMilageKm = currentMilage,
                CustomerInfo = new CustomerInfo() { PersonNummer = "1980-01-01" },
                VehicleTypeName = vehicleTypeToRent
            };
            var rentalReceipt = RentalService.RentVehicle(rentalRequest);
            Assert.IsTrue(rentalReceipt.Status == ERentalRequestStatus.NotOk);

            Assert.IsTrue(rentalReceipt.Message ==
                string.Format("The vehicle type {0} does not exist.", vehicleTypeToRent));
        }
        private RentalReceipt RentItem_CheckArguments(RentalRequest rentalRequest, IVehicleType vehicleType)
        {
            if (vehicleType == null)
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = string.Format("The vehicle type {0} does not exist.", rentalRequest.VehicleTypeName)
                };
            }

            if (string.IsNullOrEmpty(rentalRequest.RegNo))
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = "RegNo can not be empty."
                };
            }

            if (string.IsNullOrEmpty(rentalRequest.CustomerInfo.PersonNummer))
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = "PersonNummer can not be empty."
                };
            }

            if (rentalRequest.CurrentMilageKm < 0)
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = "Milage can not be < 0 km."
                };
            }

            if (_rentalsRepository.VehicleIsOutForRent(rentalRequest.RegNo))
            {
                return new RentalReceipt()
                {
                    Status = ERentalRequestStatus.NotOk,
                    Message = string.Format("Vehicle with RegNo {0} can not be rented as it is already out for rent.", rentalRequest.RegNo)
                };
            }

            return new RentalReceipt() { Status = ERentalRequestStatus.Ok };
        }