public void GetAvailableSitesFromCampgroundTest() { //Arrange SiteSqlDal siteSqlDal = new SiteSqlDal(connectionString); //Act DateTime checkIn = new DateTime(2100, 1, 1); DateTime checkOut = new DateTime(2100, 5, 1); List <Site> sites = siteSqlDal.GetAvailableSitesFromCampground(1, checkIn, checkOut); //Assert Assert.IsNotNull(sites, "Sites list is empty!"); //Since GetAvailableSitesFromCampground caps at 5, cap our site-count at 5 here if (availableSiteCount > 5) { availableSiteCount = 5; } Assert.AreEqual(availableSiteCount, sites.Count, $"Expected a count of {availableSiteCount} for sites"); }
public void SearchForAvailableReservationScreen(Park park) { SiteSqlDal siteSqlDal = new SiteSqlDal(DatabaseConnection); CampgroundSqlDal campgroundSqlDal = new CampgroundSqlDal(DatabaseConnection); ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection); List <Campground> campgrounds = campgroundSqlDal.GetAllCampgroundsFromPark(park.Id); //Search for valid campground bool done = false; while (!done) { Console.Clear(); Console.WriteLine("Search for Campground Reservation: "); PrintAllCampgroundInfoInPark(park); int userInputCampgroundId = CLIHelper.GetInteger("\nWhich Campground number (Enter 0 to cancel)?"); if (userInputCampgroundId == 0) { Console.WriteLine("Cancelled! Press any key to continue."); Console.ReadKey(); return; } if (GetCampgroundById(userInputCampgroundId, campgrounds) == null) { Console.WriteLine("Not a valid campground! Press any key to continue."); Console.ReadKey(); return; } //Once valid campground has been chosen --> Get good dates for query DateTime checkIn = CLIHelper.GetDateTime("Check-in date: "); DateTime checkOut = CLIHelper.GetDateTime("Check-out date: "); List <Site> availableSitesFromCampgrounds = new List <Site>(); bool gotDates = false; bool showReservationPrompt = false; while (!gotDates) { availableSitesFromCampgrounds = siteSqlDal.GetAvailableSitesFromCampground(userInputCampgroundId, checkIn, checkOut); if (checkOut.CompareTo(checkIn) <= 0) { Console.WriteLine("Cannot check-out earlier or same day as check-in. Press any key to continue"); Console.ReadKey(); showReservationPrompt = false; gotDates = true; //could allow user a choice to return or enter new dates } else if (availableSitesFromCampgrounds.Count < 1) { string dateReset = CLIHelper.GetString("\nThere are no available sites. \nWould you like to enter an alternate date range?\n\tYes or No?").ToLower(); if (dateReset == "yes" || dateReset == "y") { Console.WriteLine(); checkIn = CLIHelper.GetDateTime("Check-in date: "); checkOut = CLIHelper.GetDateTime("Check-out date: "); gotDates = false; } else if (dateReset == "no" || dateReset == "n") { gotDates = true; } else { Console.WriteLine("Invalid input. Try again"); gotDates = false; } } else { showReservationPrompt = true; gotDates = true; } } if (showReservationPrompt) { int daysReserved = checkOut.Subtract(checkIn).Days; Console.WriteLine("Site Id".PadRight(10) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(20) + "Utility".PadRight(15) + "Cost\n"); foreach (Site site in availableSitesFromCampgrounds) { Console.WriteLine(site.GetPrintString(daysReserved, GetCampgroundById(userInputCampgroundId, campgrounds).DailyFee)); } Console.WriteLine(); MakeReservationPrompts(checkIn, checkOut, availableSitesFromCampgrounds); done = true; } } }