public void TestCalculation3() { var total = RentalFunctions.CalculateTotalCost(new Rental() { RentedBike = new Bike { RentalPriceFirstHour = 100, RentalPriceExtraHour = 33 }, RentStartTime = new DateTime(2018, 2, 14, 8, 15, 0), RentEndTime = new DateTime(2018, 2, 14, 8, 25, 0) }); Assert.AreEqual(0, total); }
public IActionResult End(int rentalId) { // Get Rental from RentalId Rental rent = dbContext.Rentals.Include("RentedBike").Where(r => r.RentalId == rentalId && r.RentedBike != null).FirstOrDefault(); if (rent == null) { return(StatusCode(400, "Rental does not exist")); } // Get the rented Bike from the RentalId Bike rentedBike = dbContext.Rentals.Where(r => r.RentalId == rentalId).Select(r => r.RentedBike).FirstOrDefault(); // Set the missing parameters to end the rental rent.RentEndTime = DateTime.Now; rent.TotalCost = RentalFunctions.CalculateTotalCost(rent); rentedBike.DateOfLastService = (DateTime)rent.RentEndTime; dbContext.SaveChanges(); return(StatusCode(200, rent)); }