Beispiel #1
0
        public void MakeReservationTest()
        {
            //Arrange
            ReservationSqlDal reservationSqlDal = new ReservationSqlDal(connectionString);
            int      siteId       = 1;
            string   name         = "Test Reservation";
            DateTime checkInDate  = new DateTime(2100, 1, 1);
            DateTime checkOutDate = new DateTime(2100, 1, 5);

            //Act
            int reservationId = reservationSqlDal.MakeReservation(siteId, name, checkInDate, checkOutDate);

            //Assert
            Assert.AreNotEqual(0, reservationId);
        }
        public void MakeReservationPrompts(DateTime checkInDate, DateTime checkOutDate, List <Site> availableSites)
        {
            ReservationSqlDal reservationSqlDal = new ReservationSqlDal(DatabaseConnection);
            int siteToReserve = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?");

            //quit if zero
            if (siteToReserve == 0)
            {
                Console.WriteLine("Cancelled! Press any key to continue.");
                return;
            }

            //check if non-zero response is actually available
            bool isValidSite = false;

            foreach (Site site in availableSites)
            {
                if (site.Id == siteToReserve)
                {
                    isValidSite = true;
                }
            }

            //display message if site chosen was invalid
            if (!isValidSite)
            {
                Console.WriteLine("\nInvalid site or site not available, please try another campsite. \nPress any key to continue: ");
            }
            else
            {
                string reservationName = CLIHelper.GetString("What name should the reservation be made under?");
                int    confirmationId  = reservationSqlDal.MakeReservation(siteToReserve, reservationName, checkInDate, checkOutDate);
                if (confirmationId != 0)
                {
                    Console.WriteLine($"The reservation has been made and the confirmation id is {confirmationId}");
                }
                else
                {
                    Console.WriteLine($"Error: The reservation was not made");
                }
                Console.WriteLine("\nPress any key to continue");
            }
            Console.ReadKey();
            return;
        }