public ReturnReceipt MakeRentalReturn(string rentalNumber, double currentMilage, DateTime returnDateTime, IRentalService rentalService) { var returnRequest = new ReturnRequest() { CurrentMilageKm = currentMilage, RentalNumber = rentalNumber, ReturnDateTime = returnDateTime, }; var returnReceipt = rentalService.ReturnVehicle(returnRequest); return returnReceipt; }
public ReturnReceipt ReturnVehicle(ReturnRequest returnRequest) { var rentalInfo = _rentalsRepository.GetRental(returnRequest.RentalNumber); var receiptFromArgCheck = ReturnItem_CheckArguments(returnRequest, rentalInfo); if (receiptFromArgCheck.Status == ERentalReturnStatus.NotOk) { return receiptFromArgCheck; } rentalInfo = _rentalsRepository.UpdateRentalAsReturned(returnRequest.RentalNumber, returnRequest.ReturnDateTime, returnRequest.CurrentMilageKm); return new ReturnReceipt() { Status = ERentalReturnStatus.Ok, Message = string.Format("Rental with number {0} returned OK.",returnRequest.RentalNumber)}; }
public void Test_make_return_with_invalid_rental_number() { var returnRequest = new ReturnRequest() { RentalNumber = "ABGSDFKN" }; // Make a rental return var returnReceipt = RentalService.ReturnVehicle(returnRequest); Assert.IsTrue(returnReceipt.Status == ERentalReturnStatus.NotOk); Assert.IsTrue(returnReceipt.Message == string.Format("Rental with number {0} does not exist in the system.", returnRequest.RentalNumber)); }
private ReturnReceipt ReturnItem_CheckArguments(ReturnRequest returnRequest, RentalInfo rentalInfo) { if (rentalInfo == null) { return new ReturnReceipt() { Status = ERentalReturnStatus.NotOk, Message = string.Format("Rental with number {0} does not exist in the system.", returnRequest.RentalNumber) }; } if (rentalInfo.Status == RentalInfo.ERentStatus.Returned) { return new ReturnReceipt() { Status = ERentalReturnStatus.NotOk, Message = "The vehicle is already registred as returned." }; } if (returnRequest.ReturnDateTime < rentalInfo.RentalDate) { return new ReturnReceipt() { Status = ERentalReturnStatus.NotOk, Message = "Return date can not be before rental date." }; } if (returnRequest.CurrentMilageKm < rentalInfo.OriginalMileageKm) { return new ReturnReceipt() { Status = ERentalReturnStatus.NotOk, Message = "Milage on returned vehicle can not be less than original milage." }; } return new ReturnReceipt() { Status = ERentalReturnStatus.Ok }; }