private bool BookReservation(List <int> availableSiteNumbers, DateTime startDate, DateTime endDate) { CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(); bool successfullyBooked = false; Console.WriteLine(); int siteToReserve = CLIHelper.GetInteger("Which site should be reserved(enter 0 to cancel) ?"); //Return to previous screen if user enters 0 if (siteToReserve == int.Parse(command_Cancel)) { return(successfullyBooked); } while (!(availableSiteNumbers.Contains(siteToReserve))) { siteToReserve = CLIHelper.GetInteger("Invalid site choice. Which site should be reserved(enter 0 to cancel)?"); } string reservationName = CLIHelper.GetString("What name should the reservation be made under?"); int?reservationId = null; reservationId = campgroundDAL.BookReservation(reservationName, siteToReserve, startDate, endDate); if (reservationId.HasValue) { bool returnToPrevious = false; do { Console.WriteLine(); Console.WriteLine($"The reservation has been made and the confirmation id is {reservationId}"); Console.WriteLine(); Console.WriteLine("Press (Enter) Return to previous screen"); char userInput = Console.ReadKey().KeyChar; returnToPrevious = userInput == (char)Keys.Return ? true : false; } while (!returnToPrevious); successfullyBooked = true; } else { Console.WriteLine("Reservation attempt failed."); Console.WriteLine("Would you like to enter another date?: "); Console.ReadKey(); } return(successfullyBooked); }
public void BookReservationTest() { //Arrange CampgroundSqlDAL campgroundSqlDAL = new CampgroundSqlDAL(); DateTime dt1 = new DateTime(2018, 3, 3, 0, 0, 0); DateTime dt2 = new DateTime(2018, 3, 5, 0, 0, 0); //Act int?confirmation = null; confirmation = campgroundSqlDAL.BookReservation("Dalton", 43, dt1, dt2); //Assert Assert.AreEqual(true, confirmation.HasValue); }