public void ReturnNoSitesTest() { SiteSqlDAL testSite = new SiteSqlDAL(connectionString); List <Site> siteList = testSite.GetTopFiveSites(37, new System.DateTime(2018, 10, 15), new System.DateTime(2018, 10, 20)); Assert.AreEqual(0, siteList.Count); }
public static int GetSiteInteger(string message, string connectionString, int selectedCampgroundId, DateTime desiredStartDate, DateTime desiredEndDate) { string userInput = String.Empty; int intValue = 0; int numberOfAttempts = 0; SiteSqlDAL siteDal = new SiteSqlDAL(connectionString); List <Site> sitesForSelectedCampground = siteDal.GetListOfTop5AvailableSitesAtCampground(selectedCampgroundId, desiredStartDate, desiredEndDate); List <int> availableSiteIds = new List <int>(); foreach (Site site in sitesForSelectedCampground) { availableSiteIds.Add(site.Site_Id); } do { if (numberOfAttempts > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" Invalid input. Please try again\n"); Console.ForegroundColor = ConsoleColor.White; } Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write(message); Console.ForegroundColor = ConsoleColor.White; userInput = Console.ReadLine(); numberOfAttempts++; Console.WriteLine(); }while (!int.TryParse(userInput, out intValue) || (!availableSiteIds.Contains(intValue))); return(intValue); }
public void AnyAvailable() { SiteSqlDAL siteSqlDAL = new SiteSqlDAL(dbconnectionString); List <Site> testSiteList = siteSqlDAL.ReservationAvailable(4, "3/3/2018", "3/5/2018"); Assert.AreNotEqual(testSiteList.Count, 0); }
public void GetAvailableSites_AdjacentToNext_IsAvailable() { using (TransactionScope transaction = new TransactionScope()) { // Arrange ManualInitialize(); SiteSqlDAL testClass = new SiteSqlDAL(connectionString); DateTime testStartDate = new DateTime(2000, 6, 10).Date; DateTime testEndDate = new DateTime(2000, 6, 20).Date; DateTime conflictStartDate = new DateTime(2000, 6, 20).Date; DateTime conflictEndDate = new DateTime(2000, 6, 30).Date; ReservationSqlDAL rDal = new ReservationSqlDAL(connectionString); Reservation tempReservation = new Reservation(); tempReservation.Site_Id = siteId; tempReservation.Name = "TEMP RESERVATION"; tempReservation.From_Date = conflictStartDate; tempReservation.To_Date = conflictEndDate; rDal.AddReservation(tempReservation); // Act List <Site> availableSites = testClass.GetAvailableSites(testCamp, testStartDate, testEndDate); // Assert Assert.AreEqual(1, availableSites.Count); } }
public void ReservationConfirmationForPark(string arrivalDate, string departureDate, int camp_id, int parkSelection) { SiteSqlDAL site = new SiteSqlDAL(databaseconnectionString); ReservationSqlDAL bookReservation = new ReservationSqlDAL(databaseconnectionString); Console.WriteLine(); Console.Write("Which campground should be reserved? (enter 0 to cancel) "); int campInput = CLI_Helper.GetInteger("==>"); if (campInput == 0) { return; } Console.WriteLine(); Console.Write("Which camp site should be reserved? (enter 0 to cancel) "); int siteInput = CLI_Helper.GetInteger("==>"); if (siteInput == 0) { return; } Console.WriteLine(); Console.Write("Under what name should the reservation be held? "); string inputName = Console.ReadLine(); bookReservation.MakeReservation(parkSelection, site.GetSiteID(siteInput, camp_id), inputName, arrivalDate, departureDate); string reservationID = bookReservation.GetReservationId(inputName); Thread.Sleep(2000); Console.WriteLine(); Console.WriteLine($"The reservation has been booked and the confirmation ID is: {reservationID}"); Console.ReadLine(); }
// method that displays sites availabe during the selected date range // private List <Site> ViewAvailableSites(Campground campground, DateTime arrival, DateTime departure) { SiteSqlDAL dal = new SiteSqlDAL(connectionString); List <Site> sites = dal.GetAvailableSites(campground, arrival, departure); // following 3 lines calculate the rate for the chosen span of dates // decimal rate = campground.daily_fee; int days = (arrival - departure).Days; decimal cost = rate * days; Console.WriteLine(); Console.WriteLine("Results Matching Your Search Criteria:"); Console.WriteLine(); Console.WriteLine("------------------------------------------------------------------------------------------"); Console.WriteLine("| {0,2} | {1,13} | {2,20} | {3,14} | {4,13} | {5,9} |", $"ID", $"Max Occupancy", $"Handicap Accessible", $"Max RV Length", $"Has Utilities", $"Cost"); Console.WriteLine("------------------------------------------------------------------------------------------"); if (sites.Count > 0) { for (int i = 0; i < sites.Count; i++) { Console.WriteLine("| {0,2} | {1,13} | {2,20} | {3,14} | {4,13} | {5,9} |", $"{i + 1}", $"{sites[i].max_occupancy.ToString()}", $"{sites[i].acessible.ToString()}", $"{sites[i].max_rv_length.ToString()}", $"{sites[i].utilities.ToString()}", $"{cost.ToString("C")}"); } } else { Console.WriteLine("**** NO RESULTS ****"); } Console.WriteLine("------------------------------------------------------------------------------------------"); return(sites); }
public void GetTop5SitesTest() { SiteSqlDAL siteDal = new SiteSqlDAL(connectionString); List <Site> top5 = siteDal.GetTop5Sites(); Assert.AreEqual(5, top5.Count); }
private void Reservation(int campgroundId) { DateTime arrivalInput = CLIHelper.GetDateTime("What is your desired arrival date?(MM/DD/YYYY)"); DateTime fromDate = Convert.ToDateTime(arrivalInput); DateTime departureInput = CLIHelper.GetDateTime("When would you like to leave?(MM/DD/YYYY)"); DateTime toDate = Convert.ToDateTime(departureInput); Console.WriteLine("Showing available sites "); SiteSqlDAL sal = new SiteSqlDAL(connectionString); List <Site> allCampSites = sal.CampsiteAvailability(campgroundId, fromDate, toDate); if (allCampSites.Count() <= 0) { Console.WriteLine("No available camp sites! Please make a new selection."); return; } else { foreach (Site s in allCampSites) { Console.WriteLine(); Console.WriteLine("SiteId " + s.SiteID); Console.WriteLine("Campground_Id " + s.CampgroundID); Console.WriteLine("SiteNumber " + s.SiteNumber); Console.WriteLine("MaxOccupancy " + s.MaxOccupancy); Console.WriteLine("Handicap Accessible " + s.Accessible); Console.WriteLine("MaxRvLength " + s.MaxRvLength); Console.WriteLine("Utilities are available " + s.Utilities); } ReservationSqlDAL ral = new ReservationSqlDAL(connectionString); campgroundPrice = (ral.CostOfCampground(campgroundId) * (toDate.DayOfYear - fromDate.DayOfYear)); Console.WriteLine("The total fee for these sites are: " + campgroundPrice.ToString("C")); Console.WriteLine(); int campSiteInput = CLIHelper.GetInteger("What Camp site are you booking for?"); Console.WriteLine(); string nameInput = CLIHelper.GetString("What name should the reservation be under?"); Console.WriteLine(); DateTime createDate = DateTime.Now; int wasReservationSuccessful = ral.MakeReservations(campSiteInput, nameInput, fromDate, toDate, createDate); if (wasReservationSuccessful > 0) { Console.WriteLine("Success!"); Console.WriteLine("Here is your conformation ID: " + wasReservationSuccessful); } else { Console.WriteLine("Sorry but that site is alreaday booked. Please try again."); } } }
/// <summary> /// SearchCampSites method calls the GetSites method from the SiteSqlDAL and pass it to a list which we then call in the if statement /// and if count > 0 we then print out the appropriate response and we again use the foreach loop to print out the results from the /// database. we also use the CLIhelper again to take in the user input. /// </summary> private void SearchCampSites() { int campgroundId = CLIHelper.GetInteger("Which campground (enter 0 to cancel)? "); DateTime startDate = CLIHelper.GetDateTime("What is the arrival date? (YYYY/MM/DD): "); DateTime endDate = CLIHelper.GetDateTime("What is the departure date? (YYYY/MM/DD): "); //double totalDays = (endDate - startDate).TotalDays; SiteSqlDAL dal = new SiteSqlDAL(DatabaseConnection); List <Site> allSites = dal.GetSites(campgroundId, startDate, endDate); if (allSites.Count > 0) { Console.WriteLine(); Console.WriteLine("Site Number".PadRight(14) + "Max Occupancy".PadRight(15) + "Accessible".PadRight(15) + "Max RV Length".PadRight(17) + "Utilities".PadRight(16) + "Cost".PadRight(15)); Console.WriteLine(); allSites.ForEach(theseSites => { Console.WriteLine(theseSites); }); } else { Console.WriteLine("There was an error with your inputs..."); } }
/// <summary> /// Select from available sites in selected campground /// </summary> /// <param name="campground"></param> /// <param name="arrival"></param> /// <param name="departure"></param> private void SiteSelectionMenu(Campground campground, DateTime arrival, DateTime departure) { Reservation reserve = new Reservation(); reserve.FromDate = arrival; reserve.ToDate = departure; bool quit = false; while (!quit) { SiteSqlDAL siteSqlDAL = new SiteSqlDAL(_connectionString); List <Site> resList = siteSqlDAL.GetAvailalableSitesInCampground(campground.CampgroundId, arrival, departure); TimeSpan interval = reserve.ToDate - reserve.FromDate; decimal cost = interval.Days * campground.DailyFee; if (resList.Count == 0) { Console.WriteLine("\nNo sites available for the dates provided."); } else { DisplayAvailableSites(resList, cost); reserve.SiteId = 0; int selection = CLIHelper.GetInteger("Which site should be reserved (enter 0 to cancel)?"); if (selection < 0) { Console.WriteLine(" Invalid selection. Please try again."); } //else if (selection == 0) //{ // quit = true; //} else if (selection > 0) { //var site = resList.Find(m => m.SiteId == selection); for (int i = 0; i < resList.Count; i++) { if (resList[i].SiteNumber == selection) { reserve.SiteId = resList[i].SiteId; } } if (reserve.SiteId == 0) { Console.WriteLine(" Invalid selection. Please try again."); } } Console.WriteLine("What name Should the reservation be made under?"); reserve.Name = Console.ReadLine(); ReservationSqlDAL reservationSqlDAL = new ReservationSqlDAL(_connectionString); reserve = reservationSqlDAL.AddReservation(reserve); Console.WriteLine($"The reservation has been made and the confirmation id is {reserve.ReservationId}"); quit = true; } } }
/// <summary> /// Displays available campsites within a campground based on the user's selection and options /// </summary> /// <param name="campId"></param> /// <param name="arriveDate"></param> /// <param name="departDate"></param> public void DisplayAvailableSites(int campId, DateTime arriveDate, DateTime departDate) { SiteSqlDAL siteDal = new SiteSqlDAL(DatabaseConnection); List <Site> sites = siteDal.GetCampgroundSites(campId, arriveDate, departDate); bool timeToExit = false; while (!timeToExit) { if (sites.Count == 0) { Console.WriteLine("There are no available sites on that date, try again."); Console.ReadKey(); Console.Clear(); Header(); timeToExit = true; //CampgroundReservation(_parks[campId]); } else { int numDays = (int)(departDate - arriveDate).TotalDays + 1; decimal totalCost = _campgrounds[campId - 1].CalculateCost(_campgrounds[campId - 1], numDays); Console.Clear(); Header(); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine(); Console.WriteLine($"{siteNo,6} | {maxOcc,9} | {access,9} | {rvLngth,9} | {utility,9} | {cost,9}"); for (int i = 0; i < sites.Count; i++) { Console.WriteLine($"{sites[i].SiteNumber,8} | {sites[i].MaxOccupancy,10} | {sites[i].Accessible,11} | {sites[i].MaxRvLength,13} | {sites[i].Utilities,9} | {totalCost.ToString("c"),9}"); } //iterates through the Sites List to display to user Console.WriteLine(); int siteId = CLIHelper.GetInteger("Which site would you like to reserve ? (enter 0 to cancel)"); if (siteId == 0) { Console.Clear(); Header(); timeToExit = true; } Console.WriteLine(); string resName = CLIHelper.GetString("What name should your reservation be called?"); ReservationSqlDAL sqlDal = new ReservationSqlDAL(DatabaseConnection); int resConfirmationId = sqlDal.BookReservation(siteId, arriveDate, departDate, resName); Console.WriteLine(); Console.WriteLine($"The reservation has been made and your confirmation number is {resConfirmationId}"); Console.WriteLine("Click any key to exit the program."); timeToExit = true; Console.ReadKey(); } } }
public void GetAllSitesTest() { SiteSqlDAL siteDAL = new SiteSqlDAL(connectionString); List <Site> allSites = siteDAL.GetAllSites(); Assert.IsNotNull(allSites); Assert.AreEqual(sites, allSites.Count); }
public ParkSystem(string connectionString) { this.ConnectionString = connectionString; campgroundDAL = new CampgroundSqlDAL(ConnectionString); campsiteDAL = new SiteSqlDAL(ConnectionString); parkDAL = new ParkSqlDAL(ConnectionString); reservationDAL = new ReservationSqlDAL(ConnectionString); }
public void GetSitesTest() { SiteSqlDAL dal = new SiteSqlDAL(ConnectionString); var site = dal.GetSites(1, 1); Assert.AreEqual(1, site.Count); }
public void GetValuesTest() { SiteSqlDAL testDal = new SiteSqlDAL(connectionString); Assert.AreEqual("Yes", testDal.GetValues("True")); Assert.AreEqual("No", testDal.GetValues("False")); Assert.AreEqual("broken", testDal.GetValues("Null")); }
public void GetAllSitesTest() { SiteSqlDAL testSite = new SiteSqlDAL(connectionString); List <Site> siteList = testSite.GetSites(1, System.DateTime.Now, System.DateTime.Today); Assert.AreEqual(2, siteList[1].SiteId); Assert.AreEqual(0, siteList[3].MaxRvLength); Assert.AreEqual("No", siteList[0].Accessible); }
public void SearchMenu() { Console.WriteLine(); PrintAllCampgrounds(); Console.WriteLine(); Console.Write("Which campground (enter 0 to cancel)? "); int campgroundNum; bool isNumeric = int.TryParse(Console.ReadLine(), out campgroundNum); while (!isNumeric || campgroundNum < 0) { Console.Write("Please enter a valid selection: "); isNumeric = int.TryParse(Console.ReadLine(), out campgroundNum); Console.WriteLine(); } if (campgroundNum == 0) { ParkMenu(); } else { Console.Write("What is the arrival date? "); DateTime arrivalDate = Convert.ToDateTime(Console.ReadLine()); Console.Write("What is the departure date? "); DateTime departureDate = Convert.ToDateTime(Console.ReadLine()); SiteSqlDAL siteDAL = new SiteSqlDAL(connectionString); CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(connectionString); List <Site> siteList = siteDAL.GetAvailableSites(campgroundNum, arrivalDate, departureDate); Console.WriteLine(); Console.WriteLine("Campground".PadRight(20) + "Site No.".PadRight(15) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "RV Len".PadRight(15) + "Utility".PadRight(15) + "Cost".PadRight(15)); Campground campground = campgroundDAL.GetCampground(campgroundNum); foreach (Site site in siteList) { //string siteNa = site.Campground_id.ToString(); string siteNo = site.Site_number.ToString(); string siteMO = site.Max_occupancy.ToString(); string siteA = site.Accessible.ToString(); string siteMRV = site.Max_rv_length.ToString(); string siteU = site.Utilities.ToString(); string campNa = campground.Name.ToString(); int lenghtOfStay = (int)(departureDate - arrivalDate).TotalDays; decimal costOfStay = lenghtOfStay * campground.Daily_fee; string costOfStayString = costOfStay.ToString("C"); Console.WriteLine(campNa.PadRight(20) + siteNo.PadRight(20) + siteMO.PadRight(15) + siteA.PadRight(10) + siteMRV.PadRight(15) + siteU.PadRight(15) + costOfStayString.PadRight(5)); } ReservationMenu(arrivalDate, departureDate); } }
public void PrintCost() { SiteSqlDAL siteSqlDAL = new SiteSqlDAL(dbconnectionString); List <Site> testSiteList = siteSqlDAL.ListCampGroundSites(3); string siteCost = siteSqlDAL.PrintCost(testSiteList[0], "3/3/2018", "3/5/2018"); Assert.AreEqual("$60.00", siteCost); }
/// <summary> /// Searches for available sites at a given campground and given timespan. /// </summary> /// <param name="campground">The campground for the search taking place.</param> private List <Site> SearchForAvailableSites(Campground campground, DateTime arrivalDate, DateTime departureDate) { List <Site> availableSites = new List <Site>(); SiteSqlDAL ssDal = new SiteSqlDAL(ConnectionString); availableSites.AddRange(ssDal.GetAvailableSites(campground, arrivalDate, departureDate)); return(availableSites); }
public void SearchAvailableSitesInPark(string arrival, string departure, int parkSelection) { Console.Clear(); SiteSqlDAL reservationAvailibility = new SiteSqlDAL(databaseconnectionString); List <Site> availableSites = new List <Site>(); try { availableSites = reservationAvailibility.ReservationAvailable(arrival, departure, parkSelection); } catch (SqlException ex) { Console.WriteLine(); Console.WriteLine("Invalid input. Please try again."); Console.WriteLine(); return; } CampGroundSqlDAL campGroundsinPark = new CampGroundSqlDAL(databaseconnectionString); ParkSqlDAL park = new ParkSqlDAL(databaseconnectionString); List <Campground> printCampGrounds = new List <Campground>(); try { printCampGrounds = campGroundsinPark.GetParkCampGround(park.GetParkID(parkSelection)); } catch (SqlException ex) { Console.WriteLine(); Console.WriteLine("Invalid input. Please try again."); Console.WriteLine(); return; } Console.WriteLine(); Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine("CampGround".PadRight(32) + "Site No.".PadRight(15) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(15) + "Utility".PadRight(15) + "Cost".PadRight(15)); int camp_id = 0; foreach (Site s in availableSites) { string campName = string.Empty; foreach (Campground camp in printCampGrounds) { if (camp.Campground_id == s.Campground_id) { campName = camp.Name; camp_id = camp.Campground_id; } } Console.WriteLine((campName + " ID:" + (camp_id).ToString()).PadRight(32) + s.ToString() + reservationAvailibility.PrintCost(s, arrival, departure)); } ReservationConfirmationForPark(arrival, departure, camp_id, parkSelection); Console.ReadLine(); }
public void ReservationPerCampground() { SiteSqlDAL testSite = new SiteSqlDAL(dbconnectionString); List <Site> testListSites = new List <Site>(); testListSites = testSite.ReservationAvailable("3/3/2018", "3/5/2018", 2); Assert.AreNotEqual(0, testListSites.Count); testListSites = testSite.ReservationAvailable("3/3/2018", "3/5/2018", 3); Assert.AreEqual(0, testListSites.Count); }
public void GetSites_GetsSites() { // Arrange SiteSqlDAL SSDal = new SiteSqlDAL(ConnectionString); IList <Site> sites = new List <Site>(); // Act sites = SSDal.GetSites(1, "10/20/2018", "10/25/2018"); // Assert Assert.AreEqual(1, sites.Count); }
private void GetSites(int campgroundId, string fromDate, string toDate) { ISiteDAL sitedal = new SiteSqlDAL(DatabaseConnectionString.DatabaseString); IList <Site> sites = sitedal.GetSites(campgroundId, fromDate, toDate); string siteNum = "Site No."; string maxOccupancy = "Max Occup."; string accessible = "Accessible?"; string rvLength = "RV Length"; string utility = "Utility"; string cost = "Cost"; DateTime fromDateTime = DateTime.Parse(fromDate); DateTime toDateTime = DateTime.Parse(toDate); decimal numDaysStay = (decimal)(toDateTime - fromDateTime).TotalDays; Console.WriteLine($"{siteNum.PadRight(12)} {maxOccupancy.PadRight(13)} {accessible.PadRight(19)} {rvLength.PadRight(18)} {utility.PadRight(12)} {cost} "); for (int i = 0; i < sites.Count; i++) { if (sites[i].Accessible == 0) { accessible = "No"; } else { accessible = "Yes"; } if (sites[i].MaxRvLength == 0) { rvLength = "N/A"; } else { rvLength = sites[i].MaxRvLength.ToString(); } if (sites[i].Utilities == 1) { utility = "Yes"; } else { utility = "N/A"; } Console.WriteLine($"{sites[i].SiteNumber.ToString().PadRight(12)} {sites[i].MaxOccupancy.ToString().PadRight(14)}" + $"{accessible.PadRight(19)} {rvLength.PadRight(18)} {utility.PadRight(12)} {String.Format("{0:C2}", campgrounds[campgroundId].DailyFee * numDaysStay)}"); } }
/// <summary> /// Once a park is selected, goes to the data base and gets all the data /// for the park, its campgrounds and its sites. /// This data shouldn't change super frequently. /// </summary> /// <param name="park"></param> private void GetAllInfo(Park park) { ParkSqlDAL parkDAL = new ParkSqlDAL(DatabaseConnection); parkDAL.GetParkInfo(park); CampgroundSqlDAL campgroundDAL = new CampgroundSqlDAL(DatabaseConnection); campgroundDAL.GetCampgroundInfo(park); SiteSqlDAL siteDAL = new SiteSqlDAL(DatabaseConnection); siteDAL.GetSiteInfo(park); }
public virtual void SearchAvailableSitesInCampGround(int parkSelection, int camp_id, string arrival, string departure) { Console.Clear(); SiteSqlDAL reservationAvailibility = new SiteSqlDAL(databaseconnectionString); List <Site> availableSites = new List <Site>(); try { availableSites = reservationAvailibility.ReservationAvailable(camp_id, arrival, departure); } catch (SqlException ex) { Console.WriteLine(); Console.WriteLine("Invalid input. Please try again."); Console.WriteLine(); return; } Console.WriteLine(); if (reservationAvailibility.AnyAvailable(availableSites)) { Console.WriteLine("Results Matching Your Search Criteria"); Console.WriteLine("Site No.".PadRight(15) + "Max Occup.".PadRight(15) + "Accessible?".PadRight(15) + "Max RV Length".PadRight(15) + "Utility".PadRight(15) + "Cost".PadRight(15)); foreach (Site s in availableSites) { Console.WriteLine(s.ToString() + reservationAvailibility.PrintCost(s, arrival, departure)); } ReservationConfirmation(camp_id, arrival, departure, parkSelection); } else { Console.Write("No Available Sites. Would you like to enter alternate dates? (Y / N) "); string answer = Console.ReadLine(); if (answer.ToUpper() == "N") { menuInComplete = false; return; } else if (answer.ToUpper() == "Y") { return; } else { Console.WriteLine("Sorry I don't understand."); return; } } }
public void CampsiteAvailability() { int fakePark; int fakeCampground; int fakeSite; DateTime fakeFrom = Convert.ToDateTime("2020 / 01 / 05"); DateTime fakeTo = Convert.ToDateTime("2020 / 01 / 07"); DateTime fakeCreate = Convert.ToDateTime("10 / 06 / 2017"); DateTime fakeReservationCreate = DateTime.Now; int fakeOpenMonth = 1; int fakeCloseMonth = 11; int fakeReservation; decimal fakeMoney = 2.00M; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("Insert into Park values ('Big Fake Park', 'FAKE EVERYWHERE', '1919-02-26', 0000, 0, 'THIS IS SO FAKE ITS FUNNY')", conn); cmd.ExecuteNonQuery(); cmd = new SqlCommand("select cast(scope_identity() as int);", conn); fakePark = Convert.ToInt32(cmd.ExecuteScalar()); string fakeParkString = $"Insert into Campground values ({fakePark}, 'FAKE CAMPGROUND', {fakeOpenMonth}, {fakeCloseMonth}, {fakeMoney})"; SqlCommand cmd2 = new SqlCommand(fakeParkString, conn); cmd2.ExecuteNonQuery(); cmd2 = new SqlCommand("select cast(scope_identity() as int)", conn); fakeCampground = Convert.ToInt32(cmd2.ExecuteScalar()); string fakeCampSiteString = $"Insert into Site values ({fakeCampground}, 2, 4, 0, 10, 1)"; SqlCommand cmd3 = new SqlCommand(fakeCampSiteString, conn); cmd3.ExecuteNonQuery(); cmd3 = new SqlCommand("select cast(scope_identity() as int)", conn); fakeSite = Convert.ToInt32(cmd3.ExecuteScalar()); string fakeReservationString = $"Insert into Reservation values ({fakeSite}, 'FAKE HUMAN NAME', '2017/09/01', '2017/09/05', '10/06/2017')"; SqlCommand cmd4 = new SqlCommand(fakeReservationString, conn); cmd4.ExecuteNonQuery(); cmd4 = new SqlCommand("select cast(scope_identity() as int)", conn); fakeReservation = Convert.ToInt32(cmd4.ExecuteScalar()); } SiteSqlDAL sal = new SiteSqlDAL(connectionString); List <Site> output = sal.CampsiteAvailability(fakeCampground, fakeFrom, fakeTo); Assert.IsFalse(output.Count < 1); }
public void SiteSqlDALGetAllAvailableCampsites() { using (TransactionScope transaction = new TransactionScope()) { //Arrange int id = InsertFakeSite(); SiteSqlDAL testClass = new SiteSqlDAL(connectionString); //Act List <Site> sites = testClass.GetAllAvailableCampsites("6", DateTime.Now, DateTime.Now); //Assert Assert.AreEqual(id, sites[sites.Count - 1].Site_Id); } }
public void GetSiteInfo_Test() { SiteSqlDAL dal = new SiteSqlDAL(ConnectionString); Park testPark = new Park(1); Campground testCampground = new Campground(); testCampground.CampgroundID = 1; testPark.Campgrounds.Add(testCampground); dal.GetSiteInfo(testPark); Assert.AreEqual(1, testCampground.Sites.Count); }
/// <summary> /// Displays the sites available at the selected campground at the selected park /// </summary> /// <param name="parkId"></param> /// <param name="campgroundId"></param> /// <returns>Site number selected by user</returns> private int[] DisplayAvailableSites(int parkId, int campgroundId) { int siteNumber = 0; int siteId = 0; int[] sitePair = new int[2] { siteId, siteNumber }; while (true) { SiteSqlDAL dal = new SiteSqlDAL(DatabaseConnection); IList <Site> sites = dal.GetSites(parkId, campgroundId); if (sites.Count > 0) { Console.WriteLine("Site Number".ToString().PadRight(15) + "Max. Occupancy".ToString().PadRight(15) + "Accessible?".ToString().PadRight(15) + "Max RV Length".ToString().PadRight(15) + "Utility".ToString().PadRight(15) + "Cost".ToString()); foreach (Site site in sites) { Console.WriteLine(site.SiteNumber.ToString().PadRight(15) + site.MaxOccupancy.ToString().PadRight(15) + site.IsAccessible.ToString().PadRight(15) + site.MaxRVLength.ToString().PadRight(15) + site.HasUtilities.ToString().PadRight(15) + site.DailyFee.ToString("C2")); } } else { Console.WriteLine("**** SOLD TO PRIVATE CORPORATION-TEDDY ROOSEVELT SPINNING IN GRAVE ****"); } Console.WriteLine(); Console.Write("Which site should be reserved (enter 0 to cancel)? "); siteNumber = CLIHelper.GetInteger(Console.ReadLine()); bool validSite = false; foreach (var site in sites) { if (siteNumber == site.SiteNumber) { validSite = true; siteId = site.SiteId; sitePair[0] = siteId; sitePair[1] = site.SiteNumber; break; } } if (validSite || siteNumber == 0) { break; } } return(sitePair); }
public void GetSiteID() { SiteSqlDAL siteSqlDAL = new SiteSqlDAL(dbconnectionString); int testSite = siteSqlDAL.GetSiteID(4, 1); Assert.AreNotEqual(testSite, 0); Assert.AreEqual(4, testSite, "for CG 1, SN 4"); int testSite2 = siteSqlDAL.GetSiteID(12, 2); Assert.AreEqual(24, testSite2, "for CG 2, SN 12"); //int testSite3 = siteSqlDAL.GetSiteID(1000, 1000); //Assert.AreEqual(45, testSite3, "for CG 1000, SN 1000"); }