public void TotalStayCostTests() { //Arrange Campground campground = new Campground() { Id = 1, ParkId = 1, Name = "Testing", OpenMonths = 1, ClosedMonths = 12, DailyFee = 30.00M }; //Act decimal actualResult = campground.TotalStayCost(Convert.ToDateTime("02/24/2020"), Convert.ToDateTime("03/01/2020")); //Assert Assert.AreEqual(180.0M, actualResult); }
private void ShowReservationResults(int campground, DateTime arrivalDate, DateTime departureDate) { List <Site> availableSites = siteDAO.GetTop5AvailableSites(campground, arrivalDate, departureDate); List <Campground> campgrounds = campgroundDAO.GetCampgrounds(); Campground campground1 = new Campground(); bool campgoundOpen = campground1.IsCampgroundOpen(arrivalDate, departureDate); if (!campgoundOpen) { Console.WriteLine($"Campground is open between {campground1.DisplayMonths(campground1.OpenMonths)} and {campground1.DisplayMonths(campground1.ClosedMonths)}. Please choose a date range within that timeframe. Thank you!"); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); return; } bool isAvailable = siteDAO.HasAvailableSites(campground, arrivalDate, departureDate); if (!isAvailable) { Console.WriteLine($"The date range preferred {arrivalDate}-{departureDate} is not available. Please make another selection."); } else { Console.WriteLine($"Results Matching your Search Criteria"); Console.WriteLine("{0, -10} {1,-10} {2,-15} {3,-15} {4,-10} {5,-5}", "Site No.", "Max Occup.", "Accessible?", "Max RV Length", "Utility", "Cost"); foreach (Campground camp in campgrounds) { if (campground == camp.Id) { campground1 = camp; break; } else { continue; } } foreach (Site site in availableSites) { Console.WriteLine("{0, -10} {1,-10} {2,-15} {3,-15} {4,-10} {5,-5:C}", site.SiteId, site.MaxOccupancy, IsSiteAccessible(availableSites), MaxRVLength(availableSites), UtilitiesAvailable(availableSites), campground1.TotalStayCost(arrivalDate, departureDate)); } Console.WriteLine($"Which site whould be reserved (enter 0 to cancel)?"); string response = Console.ReadLine(); int campsite = int.Parse(response); if (campsite == 0) { return; } Console.WriteLine($"What name should the reservation be made under?"); string reservationName = Console.ReadLine(); int reservationId = reservationDAO.AddReservation(NewReservation(campsite, reservationName, arrivalDate, departureDate)); Console.WriteLine($"The reservation has been made and the confirmation id is {reservationId}. Thank you for booking with us!"); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); } }
/// <summary> /// Shows 5 campsites available for the user to select and reserve. /// Checks if the campground is open and if the dates. /// Prompts if the site is fully reserved. /// </summary> /// <param name="campgroundId"></param> /// <param name="arrivalDate"></param> /// <param name="departureDate"></param> private void ShowReservationResults(int campgroundId, DateTime arrivalDate, DateTime departureDate) { List <Site> availableSites = siteDAO.GetTop5AvailableSites(campgroundId, arrivalDate, departureDate); Campground campground = campgroundDAO.GetCampground(campgroundId); //Check that the selected campground is open for the requested dates (eg. no winter closures) bool campgoundOpen = campground.IsCampgroundOpen(arrivalDate, departureDate); if (!campgoundOpen) { Console.WriteLine($"Campground is open between {campground.DisplayMonths(campground.OpenMonths)} and {campground.DisplayMonths(campground.ClosedMonths)}. Please choose a date range within that timeframe. Thank you!"); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); return; } // Check that sites are available in database bool isAvailable = siteDAO.HasAvailableSites(campgroundId, arrivalDate, departureDate); if (!isAvailable) { Console.WriteLine($"The date range preferred {arrivalDate}-{departureDate} is not available. Please make another selection."); } else { //Display 5 available sites with details Console.WriteLine($"Results Matching your Search Criteria"); Console.WriteLine("{0, -10} {1,-10} {2,-15} {3,-15} {4,-10} {5,-5}", "Site No.", "Max Occup.", "Accessible?", "Max RV Length", "Utility", "Cost"); foreach (Site site in availableSites) { //TODO: The 3 methods IsSiteAccessible(site), MaxRVLength(site), UtilitiesAvailable(site) are just text formatting. I'd like to change these to simple ternary expressions Console.WriteLine(" {0, -10} {1,-10} {2,-15} {3,-15} {4,-10} {5,-5:C}", site.SiteId, site.MaxOccupancy, IsSiteAccessible(site), MaxRVLength(site), UtilitiesAvailable(site), campground.TotalStayCost(arrivalDate, departureDate)); } //User to choose a site to reserve Console.WriteLine($" Which site whould be reserved (enter 0 to cancel)?"); string response = Console.ReadLine(); int campsite = int.Parse(response); if (campsite == 0) { return; } //Get reservation details Console.WriteLine($" What name should the reservation be made under?"); string reservationName = Console.ReadLine(); //Add reservation to database int reservationId = reservationDAO.AddReservation(NewReservation(campsite, reservationName, arrivalDate, departureDate)); //Let user know their reservation is confirmed Console.WriteLine($" The reservation has been made and the confirmation id is {reservationId}. Thank you for booking with us!"); Console.WriteLine(" Press ENTER to continue..."); Console.ReadLine(); } }