public void Rent_InvalidCarCategory_Then_ThrowException() { var rent = new Rent() { Id = 1, PersonalIdentityNumber = "8711210057", CarCategory = CarCategory.InvalidCarCategory, StartOfRent = DateTime.Parse("2018-06-17"), StartOfCurrentMeter = 100, LicensePlate = "MBLC298" }; Assert.Throws <Exception>(() => rent.CalculateRentalPrice(200, 3)); }
/// <summary> /// Function takes the rental/booking number, /// day the car returns /// and what the meter stands on when returning the car /// </summary> /// <param name="id"></param> /// <param name="endOfRent"></param> /// <param name="endOfCurrentMeter"></param> /// <returns>The rent object</returns> public async Task <Rent> ReturnAsync(int id, DateTime endOfRent, int endOfCurrentMeter) { Rent rent = await _rentRepository.GetByIdAsync(id); if (DateTime.Compare(rent.StartOfRent, endOfRent) > 0) { throw new ArgumentException("RentService::ReturnAsync Invalid date, end date is before start date"); } if (rent.StartOfCurrentMeter > endOfCurrentMeter) { throw new ArgumentException("RentService::ReturnAsync Current meter is below starting meter"); } rent.EndOfRent = endOfRent; rent.EndofCurrentMeter = endOfCurrentMeter; Price price = await _priceRepository.GetPriceByCarCategoryAsync(rent.CarCategory); rent.Price = rent.CalculateRentalPrice(price.PerDay, price.PerKm); await _rentRepository.UpdateAsync(rent); return(rent); }