public void CheckCampgroundMonths()
        {
            // Assign
            CampgroundSqlDAO dao = new CampgroundSqlDAO(connectionString);

            // Act
            IList <Campground> list = dao.GetCampgroundById(acadia);

            // Assert
            Assert.AreEqual("January", list[0].OpenMonth);
        }
예제 #2
0
        public void GetCampgroundsTest_Should_ReturnAllCampgrounds()
        {
            // Arrange
            CampgroundSqlDAO dao = new CampgroundSqlDAO(ConnectionString);

            // Act
            IList <Campground> campgrounds = dao.GetCampgroundsByParkId(ParkId);

            // Assert
            Assert.AreEqual(2, campgrounds.Count);
        }
        public void CheckCampgroundCount()
        {
            // Assign
            CampgroundSqlDAO dao = new CampgroundSqlDAO(connectionString);

            // Act
            IList <Campground> list = dao.GetCampgroundById(acadia);

            // Assert
            Assert.AreEqual(1, list.Count);
        }
        public void GetAllCampgroundsTest()
        {
            // Arrange
            IList <Campground> cgrounds;
            ICampgroundDAO     dao = new CampgroundSqlDAO(connection);

            // Act
            cgrounds = dao.GetAllCampgrounds();

            // Assert
            Assert.AreEqual(7, cgrounds.Count);
        }
        public void GetCampgroundByIDTest()
        {
            // Arrange
            ICampgroundDAO dao = new CampgroundSqlDAO(connection);

            // Act
            Campground c = dao.GetCampgroundByID(4);

            // Assert
            Assert.AreEqual("Devil's Garden", c.Name);
            Assert.IsNull(dao.GetCampgroundByID(9));
        }
예제 #6
0
        public void TestCheckAvailability()
        {
            // arrange
            CampgroundSqlDAO dao = new CampgroundSqlDAO(connectionString);

            // act
            bool actualResult  = dao.CheckAvailability(newCampId, Convert.ToDateTime("6/1/2019"), Convert.ToDateTime("7/1/2019"));
            bool actualResult2 = dao.CheckAvailability(newCampId, Convert.ToDateTime("1/1/2019"), Convert.ToDateTime("12/1/2019"));

            // assert
            Assert.AreEqual(true, actualResult);
            Assert.AreEqual(false, actualResult2);
        }
        public void ConstructsCampgroundProperly()
        {
            //assign
            CampgroundSqlDAO   campgroundSqlDAO = new CampgroundSqlDAO(ConnectionString);
            IList <Campground> campgrounds      = campgroundSqlDAO.GetCampgrounds();


            //assert
            Assert.AreEqual(TwinPeaksParkId, campgrounds[0].Park_Id);
            Assert.AreEqual("Black Lodge", campgrounds[0].Name);
            Assert.AreEqual(01, campgrounds[0].Open_From);
            Assert.AreEqual(09, campgrounds[0].Open_To);
            Assert.AreEqual(420.00M, campgrounds[0].Daily_fee);
        }
예제 #8
0
        public void IsOpen_ShouldReturn_True_If_Campground_IsOpen(int startMonth, int endMonth, bool expected)
        {
            DateTime         startDate = new DateTime(2019, startMonth, 1);
            DateTime         endDate   = new DateTime(2019, endMonth, 1);
            CampgroundSqlDAO dao       = new CampgroundSqlDAO(base.ConnectionString);

            CampgroundModel campground = new CampgroundModel();

            campground.Open_From_MM = base.NewOpenFrom;
            campground.Open_To_MM   = base.NewOpenTo;

            bool isOpen = dao.IsOpen(campground, startDate, endDate);

            Assert.AreEqual(expected, isOpen);
        }
예제 #9
0
        public void TestGetCampgrounds()
        {
            // arrange
            CampgroundSqlDAO dao = new CampgroundSqlDAO(connectionString);

            // act
            IList <Campground> actualResult = dao.GetCampgrounds(parkId);

            // assert
            Assert.AreEqual(1, actualResult.Count);
            Assert.AreEqual("Camp Brandon", actualResult[0].Name);
            Assert.AreEqual(3, actualResult[0].OpenMonth);
            Assert.AreEqual(9, actualResult[0].CloseMonth);
            Assert.AreEqual(1000000, actualResult[0].DailyFee);
        }
        public void GetAllCampgroundsInParkTest()
        {
            // Arrange
            IList <Campground> cgrounds;
            Park p = new Park()
            {
                ParkID = 1
            };
            ICampgroundDAO dao = new CampgroundSqlDAO(connection);

            // Act
            cgrounds = dao.GetAllCampgrounds(p);

            // Assert
            Assert.AreEqual(3, cgrounds.Count);
        }
예제 #11
0
 public void GetCampgroundsByParkId(int parkID, int campgroundCount)
 {
     //Arrange
     CampgroundSqlDAO  dao   = new CampgroundSqlDAO(this.connectionString);
     List <Campground> list  = new List <Campground>();
     List <Campground> list2 = new List <Campground>();
     //int id = this.getMaxIdFromTable("park", "park_id");
     //if (id > 0)
     //{
     //    //Act
     //    list = dao.GetCampgroundsByParkId(id);
     //    list2 = dao.GetCampgroundsByParkId(id - 1);
     //    //Assert
     //    Assert.AreEqual(1, list.Count);
     //    Assert.AreEqual(3, list2.Count);
     //}
 }
예제 #12
0
        public override void Setup()
        {
            base.Setup();
            dao = new CampgroundSqlDAO(ConnectionString);
            // initialize the values of campground
            // run reader through the SQL command
            // assign values from the reader results

            // Execute the script
            //using (SqlConnection connection = new SqlConnection(ConnectionString))
            //{
            //    SqlCommand cmd = new SqlCommand(
            //        @"INSERT INTO campground (name, open_from_mm, open_to_mm, daily_fee)
            //                           VALUES('Test Name', 1, 12, 30.00);
            //           INSERT INTO site (site", connection);

            //    connection.Open();

            //    cmd.ExecuteNonQuery();
            //}
        }
        public void TestGetAllCampgroundsByParkId()
        {
            //Arrange
            CampgroundSqlDAO dao = new CampgroundSqlDAO(connectionString);

            //Act
            IList <Campground> campgrounds = dao.GetCampgroundsByParkId(newParkId);
            int i = 0;

            for (; i < campgrounds.Count; i++)
            {
                if (campgrounds[i].CampgroundId == newCampgroundId)
                {
                    break;
                }
            }

            //Assert
            Assert.AreEqual(1, campgrounds.Count);
            Assert.AreEqual("Big Trees", campgrounds[i].Name);
        }
        public void GetTop5Sites_ReturnsSites(string parkName, int campgroundSelection, int expected)
        {
            ICampgroundSqlDAO campdao = new CampgroundSqlDAO(connectionString);
            ISiteSqlDAO       sitedao = new SiteSqlDAO(connectionString);

            Park testPark = new Park();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand($"SELECT * FROM park WHERE name = '{parkName}'", conn);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        testPark.Park_ID        = Convert.ToInt32(reader["park_id"]);
                        testPark.Name           = Convert.ToString(reader["name"]);
                        testPark.Location       = Convert.ToString(reader["location"]);
                        testPark.Establish_date = Convert.ToDateTime(reader["establish_date"]);
                        testPark.Area           = Convert.ToInt32(reader["area"]);
                        testPark.Visitors       = Convert.ToInt32(reader["visitors"]);
                        testPark.Description    = Convert.ToString(reader["description"]);
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine($"There was an error {ex.Message}.");
            }
            IList <Campground> campgroundList = campdao.GetCampgroundsForPark(testPark);

            Campground campground = campgroundList.ElementAt(campgroundSelection - 1);

            IList <Site> siteList = sitedao.GetTop5SitesInCampground(campground, "06/19/2019", "06/20/2019");

            Assert.AreEqual(expected, siteList.Count);
        }
        protected override bool ExecuteSelection(string choice)
        {
            switch (choice)
            {
            case "1":
                // display campgrounds method
                ICampgroundSqlDAO   campgroundDAO = new CampgroundSqlDAO(ConnectionString);
                ParkCampgroundsMenu menu          = new ParkCampgroundsMenu(campgroundDAO, park);
                menu.Run();
                break;

            case "2":
                // Call Reservation Menu
                campgroundDAO = new CampgroundSqlDAO(ConnectionString);
                CampgroundReservationMenu menu2 = new CampgroundReservationMenu(campgroundDAO, park);
                menu2.Run();
                break;

            case "Q":
                break;
            }

            return(true);
        }
        public override void Setup()
        {
            base.Setup();
            dao = new CampgroundSqlDAO(ConnectionString);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                SqlCommand command = new SqlCommand(
                    @"  SET IDENTITY_INSERT park ON
                        INSERT INTO park (park_id, name, location, establish_date, area, visitors, description) VALUES (1, 'FakePark', 'Somewhere', '1910-10-10', 10, 10, 'fun')
                        SET IDENTITY_INSERT park OFF
                        SET IDENTITY_INSERT campground ON
                        INSERT INTO campground (campground_id, park_id, name, open_from_mm, open_to_mm, daily_fee) VALUES (1, 1, 'fakeCampground', 05, 09, 100)
                        SET IDENTITY_INSERT campground OFF
                        SET IDENTITY_INSERT site ON
                        INSERT INTO site (site_id, campground_id, site_number, max_occupancy, accessible, max_rv_length, utilities) VALUES (1, 1, 1, 10, 1, 20, 1)
                        SET IDENTITY_INSERT site OFF"
                    , connection);

                connection.Open();

                command.ExecuteNonQuery();
            }
        }
        public void Display()
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Campground Reservations");
                Console.WriteLine("-----------------------");
                Console.WriteLine();
                Console.WriteLine("#   Name".PadRight(40) + "Open".PadRight(10) + "Close".PadRight(10) + "Daily Rate");
                Console.WriteLine("".PadRight(70, '-'));

                IList <CampgroundModel> cmpg = new List <CampgroundModel>();
                cmpg = this.CampgroundSqlDAO.GetCampgrounds(Park.Park_Id);
                for (int i = 0; i < cmpg.Count; i++)
                {
                    Console.WriteLine($"{i + 1}) {cmpg[i].Name.PadRight(35)} {MonthNames[cmpg[i].Open_From_MM].PadRight(10)}{MonthNames[cmpg[i].Open_To_MM].PadRight(10)}{cmpg[i].Daily_Fee:C2}");
                }

                Console.WriteLine();
                Console.WriteLine("Pick a campground: ");
                Console.WriteLine("Q) Return to Previous Screen");
                string campgroundChoice = Console.ReadLine();

                try
                {
                    if (campgroundChoice.ToUpper() == "Q")
                    {
                        break;
                    }
                    else if (int.Parse(campgroundChoice) > cmpg.Count || int.Parse(campgroundChoice) < 1)
                    {
                        Console.WriteLine("Invalid input, try again.");
                        Console.WriteLine("Press any key to continue.");
                        Console.ReadKey();
                        continue;
                    }

                    Console.WriteLine();
                    Console.Write("What is the arrival date? (YYYY-MM-DD): ");
                    string fromDateChoice = Console.ReadLine();

                    Console.WriteLine();
                    Console.Write("What is the departure date? (YYYY-MM-DD): ");
                    string toDateChoice = Console.ReadLine();

                    int      campgroundID = int.Parse(campgroundChoice);
                    DateTime fromDate     = DateTime.Parse(fromDateChoice);
                    DateTime toDate       = DateTime.Parse(toDateChoice);
                    if (toDate < fromDate)
                    {
                        Console.WriteLine("The end date must be after the beginning date!");
                        Console.Write("Press any key to try again.");
                        Console.ReadKey();
                        continue;
                    }
                    if (!CampgroundSqlDAO.IsOpen(cmpg[campgroundID - 1], fromDate, toDate))
                    {
                        Console.WriteLine("The campground is closed during the time you have selected.");
                        Console.Write("Press any key to re-select.");
                        Console.ReadKey();
                        continue;
                    }

                    Console.Clear();
                    int reservationDays = (int)(toDate - fromDate).TotalDays + 1;

                    decimal reservationCost = (decimal)reservationDays * cmpg[campgroundID - 1].Daily_Fee;

                    Console.WriteLine("Results Matching Your Search Criteria");
                    Console.WriteLine($"Site No.".PadRight(10) + "Max Occup.".PadRight(12) + "Accessible?".PadRight(13) + "Max RV Length".PadRight(15) + "Utility".PadRight(9) + "Cost");
                    Console.WriteLine("".PadRight(63, '-'));

                    IList <CampsiteModel> availableReservations = new List <CampsiteModel>();
                    availableReservations = this.CampsiteSqlDAO.GetAvailableReservations(cmpg[campgroundID - 1], fromDate, toDate);

                    if (availableReservations.Count == 0)
                    {
                        Console.WriteLine("There are no reservations matching your criteria.");
                        Console.Write("Please press any key to make new selections.");
                        Console.ReadKey();
                        continue;
                    }

                    for (int i = 0; i < availableReservations.Count; i++)
                    {
                        CampsiteModel res = availableReservations[i];
                        Console.WriteLine($"{res.Site_Id}".PadRight(10) + $"{res.Max_Occupancy}".PadRight(12) + $"{((res.Accessible) ? "Yes" : "No")}".PadRight(13) + $"{res.Max_RV_Length}".PadRight(15) + $"{((res.Utilities) ? "Yes" : "No")}".PadRight(9) + $"{reservationCost:C2}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Please pick a Site No.: ");
                    Console.WriteLine("Q) Return to Previous Screen");
                    string choice = Console.ReadLine();
                    if (choice.ToUpper() == "Q")
                    {
                        continue;
                    }
                    int  whichCampsite = int.Parse(choice);
                    bool validCampsite = false;
                    foreach (CampsiteModel csite in availableReservations)
                    {
                        if (whichCampsite == csite.Site_Id)
                        {
                            validCampsite = true;
                        }
                    }
                    if (!validCampsite)
                    {
                        throw new Exception("Invalid campsite.");
                    }
                    Console.WriteLine();
                    Console.Write("Please enter the name for the reservation: ");
                    string camperName = Console.ReadLine();
                    if (camperName == "")
                    {
                        throw new Exception("A name must be entered.");
                    }
                    int reservationId = this.ReservationSqlDAO.PlaceReservation(camperName, whichCampsite, fromDate, toDate);
                    Console.WriteLine();
                    Console.WriteLine("Your reservation has been successfuly placed.");
                    Console.WriteLine($"The reservation ID is: {reservationId}");
                    Console.Write("Thank you for using the National Parks Reservation System!");
                    Console.ReadKey();

                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid input, try again.");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    continue;
                }
            }
        }
 public override void Setup()
 {
     base.Setup();
     dao = new CampgroundSqlDAO(ConnectionString);
 }