Exemplo n.º 1
0
        /// <summary>
        /// Prints a list of sites matching given criteria
        /// </summary>
        /// <param name="startDate">Reservation start date</param>
        /// <param name="endDate">Reservation end date</param>
        /// <param name="campgrounds">List of campgrounds to search in</param>
        /// <param name="occupants">Required number of occupants</param>
        /// <param name="isAccessible">Desired handicap accessibility</param>
        /// <param name="RVLength">Length of RV </param>
        /// <param name="hasUtilities">Desired existance of utilities</param>
        /// <returns>The list of sites.</returns>
        private List <Site> PrintSiteList(DateTime startDate, DateTime endDate, List <Campground> campgrounds, int occupants, bool isAccessible, int RVLength, bool hasUtilities)
        {
            // Initialize working variables
            List <string> screenOutput = new List <string>();
            List <Site>   allSites     = new List <Site>();
            int           menuNumber   = 1;

            // Create a header and add it to the screen output
            string header = "Site No.  Max Occup.  Accessible?  Max RV Length  Utility  Cost";

            if (campgrounds.Count > 1)
            {
                header = "Campground".PadRight(32) + header;
            }
            header = "     " + header;
            screenOutput.Add(header);

            // Find each relevant site in each campsite
            foreach (Campground campground in campgrounds)
            {
                List <Site> sites = siteDAL.FindAvailableSites(startDate, endDate, campground, occupants, isAccessible, RVLength, hasUtilities);
                foreach (Site site in sites)
                {
                    // Creaete a line to display info about each site and add it to the screen output
                    string line = site.ToString() + CLIHelper.GetTripTotal(startDate, endDate, campground.DailyFee).ToString("C");

                    if (campgrounds.Count > 1)
                    {
                        line = campground.Name.PadRight(32) + line;
                    }
                    line = $"{menuNumber,2})  " + line;
                    screenOutput.Add(line);

                    // Add the site to the output list
                    allSites.Add(site);

                    // Increment the number next to the site
                    menuNumber++;
                }
            }

            // If there are sites, write them to the screen
            if (allSites.Count != 0)
            {
                foreach (string line in screenOutput)
                {
                    Console.WriteLine(line);
                }
            }
            Console.WriteLine();

            // Return the list of found sites
            return(allSites);
        }
        public void FindAvailableSitesAdvanced(int campgroundID, int expectedOutput)
        {
            // Arrange
            SiteDAL site = new SiteDAL(ConnectionString);

            // Act
            var listOfReservations = site.FindAvailableSites(new DateTime(2019, 6, 10), new DateTime(2019, 6, 15), new Campground()
            {
                CampgroundId = campgroundID
            }, 6, true, 0, false);

            // Assert
            Assert.AreEqual(expectedOutput, listOfReservations.Count);
        }
        public void FindAvailableSites(int campgroundID, int expectedOutput)
        {
            // Arrange
            SiteDAL site = new SiteDAL(ConnectionString);

            // Act
            var listOfReservations = site.FindAvailableSites(new DateTime(2018, 4, 25), new DateTime(2018, 6, 19), new Campground()
            {
                CampgroundId = campgroundID
            });

            // Assert
            Assert.AreEqual(expectedOutput, listOfReservations.Count);
        }