public void VerifyUserIsAbleToSearchForAFlightWithInvalidInfo() { FlightSearchDataModel flightSearchDataModel = new FlightSearchDataModel { Origin = "Test", Destination = AirportsStartsWithC.CapeTownCapeTownInternationalAirport, DateFrom = LocalToday.AddMonths(1).AsLocalDate(), DateTo = LocalToday.AddMonths(2).AddDays(6).AsLocalDate() }; const string errorMessage = "From"; That.Given(_ => BaseUiSteps.IClickOnPrivacyPopupWindowAction(PrivacyPopupWindowActions.Accept)) .And(_ => BaseUiSteps.INavigateToPage(PageUriFields.Flights)) .When(_ => FlightSearchUiSteps.IClickOnOriginPanel()) .And(_ => FlightSearchUiSteps.ISelectOriginFromDropdown(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnDestinationPanel()) .And(_ => FlightSearchUiSteps.ISelectDestinationFromDropdown(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnDepartureDateInput()) .And(_ => FlightSearchUiSteps.IEnterDepartureDate(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnReturnDateInput()) .And(_ => FlightSearchUiSteps.IEnterReturnDate(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickSearchFlightsButton()) .Then(_ => FlightSearchUiSteps.IShouldSeeErrorMessage(errorMessage)) .BDDfy("Verify user is able to search for a flight with invalid info"); }
/// <summary> /// Convert a Flight object to a PricedFlight object. /// </summary> /// <param name="flight">The flight to convert and price.</param> /// <param name="searchData">The FlightSearchDataModel to be used to help calculate the price of the flight.</param> /// <param name="calculator">The IFlightPriceCalculator to be used to help calculate the price of the flight.</param> /// <returns>An asynchronous task for pricing the flight.</returns> public static async Task <PricedFlight> PriceFlightAsync(this Flight flight, FlightSearchDataModel searchData, IFlightPriceCalculator calculator) { // Create PricedFlight object. var output = new PricedFlight { Flight = flight }; // Put contents of flight and search data into SelectedFlights object // so total price can be calculated. var totalFlight = new SelectedFlights { Outbound = flight, Inbound = null, NumberAdults = searchData.NumberAdults, NumberChildren = searchData.NumberChildren, TravelClass = searchData.TravelClass }; decimal price = await calculator.CalculateTotalPriceAsync(totalFlight); output.TotalPrice = price; return(output); }
/// <summary> /// Convert this SelectedFlights object to a SelectedFlightsModel. /// </summary> /// <param name="selectedFlights">The SelectedFlights to convert.</param> /// <param name="calculator">The IFlightPriceCalculator to use to calculate flight prices.</param> public static async Task <SelectedFlightsModel> ToSelectedFlightsModel(this SelectedFlights selectedFlights, IFlightPriceCalculator calculator) { // Populate model with number of passengers and travel class. FlightSearchDataModel searchData = new FlightSearchDataModel { NumberAdults = selectedFlights.NumberAdults, NumberChildren = selectedFlights.NumberChildren, TravelClass = selectedFlights.TravelClass }; SelectedFlightsModel output = new SelectedFlightsModel { Outbound = await selectedFlights.Outbound.PriceFlightAsync(searchData, calculator), Inbound = selectedFlights.Inbound is null ? null : await selectedFlights.Inbound.PriceFlightAsync(searchData, calculator), NumberAdults = selectedFlights.NumberAdults, NumberChildren = selectedFlights.NumberChildren, TravelClass = selectedFlights.TravelClass }; output.TotalPrice = output.Outbound.TotalPrice; if (output.IsReturn) { output.TotalPrice += output.Inbound.TotalPrice; } return(output); } }
private void IncrementAdults(FlightSearchDataModel travelers) { int count = travelers.Travelers.Adults; int actualValue = Convert.ToInt32(FindElement(string.Format(TravelerElementValue, "adults")).GetAttribute("Value")); if (!count.Equals(null) && !actualValue.Equals(count)) { if (actualValue.Equals(1)) { count = count - 1; for (int i = 0; i < count; i++) { Element incrementAdult = FindElement(string.Format(TravelerIncrementer, "adults")); incrementAdult.WaitForToBeClickable(); incrementAdult.Click(); } } else { for (int i = 0; i < count; i++) { Element incrementAdult = FindElement(string.Format(TravelerIncrementer, "adults")); incrementAdult.WaitForToBeClickable(); incrementAdult.Click(); } } } }
private void SelectBaggage(FlightSearchDataModel additionalInfo) { BaggageCount.Click(); IncrementCabinBag(additionalInfo); IncrementCheckedBag(additionalInfo); BaggageCount.SendKeys(Keys.Enter); }
/// <summary> /// Convert a FlightSearchDataModel to a SearchFilterParameters object. /// </summary> /// <param name="flightSearchDataModel">The FlightSearchDataModel to convert.</param> /// <param name="dataAccess">The IDataAccess to use to obtain Airports from Ids.</param> /// <returns>An asynchronous task for finding converting the FlightSearchDataModel.</returns> public static async Task <SearchFilterParameters> ToSearchFilterParameters(this FlightSearchDataModel flightSearchDataModel, IDataAccess dataAccess) { // Get Airport objects from database using their Ids. Airport originAirport = await dataAccess.FindAirportByIdAsync(flightSearchDataModel.SelectedOriginAirportId.Value); Airport destinationAirport = await dataAccess.FindAirportByIdAsync(flightSearchDataModel.SelectedDestinationAirportId.Value); // Set inbound date to the value in the model if return flight, // otherwise the inbound date is a default DateTime(). DateTime inboundDate = new DateTime(); if (flightSearchDataModel.ReturnFlight == true) { inboundDate = flightSearchDataModel.InboundDate.Value; } // Map SearchFilterModel to SearchFilterParameters. SearchFilterParameters output = new SearchFilterParameters { OriginAirport = originAirport, DestinationAirport = destinationAirport, OutDate = flightSearchDataModel.OutboundDate, InDate = inboundDate }; return(output); }
public async Task <ActionResult> ChangeDate(string ticks) { // Parse ticks string into new datetime object. DateTime newOutDate = new DateTime(long.Parse(ticks)); FlightSearchDataModel searchData = (FlightSearchDataModel)Session["searchData"]; if (searchData is null) { return(View("Index")); } // Calculate difference between dates. TimeSpan dateDifference = newOutDate - searchData.OutboundDate; // Add difference to inbound and outbound dates. searchData.OutboundDate += dateDifference; if (searchData.ReturnFlight == true) { searchData.InboundDate += dateDifference; } await FillModel(searchData); return(View("Index", searchData)); }
internal void FillAdditionalTravelInfo(FlightSearchDataModel additionalInfo) { SelectTripType(additionalInfo); SelectTravelers(additionalInfo); SelectCabinClass(additionalInfo); SelectBaggage(additionalInfo); }
private void SelectTravelers(FlightSearchDataModel travelerInfo) { TraverlersCount.Click(); IncrementAdults(travelerInfo); IncrementStudents(travelerInfo); IncrementYouths(travelerInfo); IncrementChildren(travelerInfo); IncrementToddlers(travelerInfo); IncrementInfants(travelerInfo); TraverlersCount.SendKeys(Keys.Enter); }
private void IncrementChildren(FlightSearchDataModel travelers) { if (!travelers.Travelers.Children.Equals(null)) { for (int i = 0; i < travelers.Travelers.Children; i++) { Element incrementChild = FindElement(string.Format(TravelerIncrementer, "child")); incrementChild.WaitForToBeClickable(); incrementChild.Click(); } } }
private void IncrementYouths(FlightSearchDataModel travelers) { if (!travelers.Travelers.Youths.Equals(null)) { for (int i = 0; i < travelers.Travelers.Youths; i++) { Element incrementYouth = FindElement(string.Format(TravelerIncrementer, "youth")); incrementYouth.WaitForToBeClickable(); incrementYouth.Click(); } } }
private void IncrementStudents(FlightSearchDataModel travelers) { if (!travelers.Travelers.Students.Equals(null)) { for (int i = 0; i < travelers.Travelers.Students; i++) { Element incrementStudents = FindElement(string.Format(TravelerIncrementer, "students")); incrementStudents.WaitForToBeClickable(); incrementStudents.Click(); } } }
private void IncrementCheckedBag(FlightSearchDataModel additionalInfo) { if (!additionalInfo.Baggage.CheckedBag.Equals(null)) { for (int i = 0; i < additionalInfo.Baggage.CheckedBag; i++) { Element incrementCheckedBags = FindElement(string.Format(CabinClassIncrementer, "checked-bag")); incrementCheckedBags.WaitForToBeClickable(); incrementCheckedBags.Click(); } } }
private void IncrementToddlers(FlightSearchDataModel travelers) { if (!travelers.Travelers.ToddlerInOwnSeat.Equals(null)) { for (int i = 0; i < travelers.Travelers.ToddlerInOwnSeat; i++) { Element incrementSeatInfant = FindElement(string.Format(TravelerIncrementer, "seatInfant")); incrementSeatInfant.WaitForToBeClickable(); incrementSeatInfant.Click(); } } }
private void IncrementInfants(FlightSearchDataModel travelers) { if (!travelers.Travelers.InfantOnLap.Equals(null)) { for (int i = 0; i < travelers.Travelers.InfantOnLap; i++) { Element incrementLapInfant = FindElement(string.Format(TravelerIncrementer, "lapInfant")); incrementLapInfant.WaitForToBeClickable(); incrementLapInfant.Click(); } } }
public async Task <ActionResult> FeaturedDestinations(string featuredDestination) { var flightSearchDataModel = new FlightSearchDataModel(); // Set airports list in search filter model. flightSearchDataModel.Airports = await GetAirportSelectListAsync(); // Get List<Airport> var airports = await _dataAccess.GetAirportsAsync(); // Get the origin airport (LHR). Airport origin = airports.Where(x => x.AirportCode == "LHR").First(); Airport destination = null; switch (featuredDestination) { case "paris": destination = airports.Where(x => x.AirportCode == "CDG").First(); break; case "new york": destination = airports.Where(x => x.AirportCode == "JFK").First(); break; case "amsterdam": destination = airports.Where(x => x.AirportCode == "AMS").First(); break; default: return(View("Index")); } // Set origin and destination ids. flightSearchDataModel.SelectedOriginAirportId = origin.Id; flightSearchDataModel.SelectedDestinationAirportId = destination.Id; flightSearchDataModel.ReturnFlight = true; // Depart a week from now and return the week after that by default. flightSearchDataModel.OutboundDate = DateTime.Today.AddDays(7); flightSearchDataModel.InboundDate = DateTime.Today.AddDays(14); // Fill model with flights. await FillModel(flightSearchDataModel); // Add search data to session so it can be used later. Session.Add("searchData", flightSearchDataModel); return(View("Index", flightSearchDataModel)); }
public async Task <ActionResult> Index() { var flightSearchDataModel = new FlightSearchDataModel(); // Set airports list in search filter model. flightSearchDataModel.Airports = await GetAirportSelectListAsync(); // GET request so no airports have been selected. // Set outbound and inbound flights to null. flightSearchDataModel.OutboundFlights = null; flightSearchDataModel.InboundFlights = null; return(View(flightSearchDataModel)); }
public async Task <ActionResult> Index(FlightSearchDataModel flightSearchDataModel) { // Repopulate drowdown list box. flightSearchDataModel.Airports = await GetAirportSelectListAsync(); // Check if model is invalid. if (!ModelState.IsValid) { return(View(flightSearchDataModel)); } // Model is valid. // Add search data to session so it can be used later. Session.Add("searchData", flightSearchDataModel); await FillModel(flightSearchDataModel); return(View(flightSearchDataModel)); }
/// <summary> /// Populate a FlightSearchDataModel with airports, etc. from the database. /// </summary> /// <param name="flightSearchDataModel">The object to populate.</param> private async Task FillModel(FlightSearchDataModel flightSearchDataModel) { // Clear out existing items in lists. flightSearchDataModel.CheapestPricesOnSimilarDates = new Dictionary <DateTime, decimal>(); flightSearchDataModel.OutboundFlights = new List <PricedFlight>(); flightSearchDataModel.InboundFlights = new List <PricedFlight>(); var searchFilterParameters = await flightSearchDataModel.ToSearchFilterParameters(_dataAccess); // Set cheapest prices on similar dates. flightSearchDataModel.CheapestPricesOnSimilarDates = await _flightManager.FindCheapestPricesOnSimilarDatesAsync(searchFilterParameters, 2); // Set outbound flight list. List <Flight> outboundFlights = await _flightManager.FindOutboundFlightsAsync(searchFilterParameters); foreach (var flight in outboundFlights) { // Loop through and price each flight then add it to model list. flightSearchDataModel.OutboundFlights.Add(await flight.PriceFlightAsync(flightSearchDataModel, _priceCalculator)); } // Set inbound flight list. if (flightSearchDataModel.ReturnFlight == true) { // Flight is return flight. List <Flight> inboundFlights = await _flightManager.FindInboundFlightsAsync(searchFilterParameters); foreach (var flight in inboundFlights) { // Loop through and price each flight then add it to model list. flightSearchDataModel.InboundFlights.Add(await flight.PriceFlightAsync(flightSearchDataModel, _priceCalculator)); } } else { // Not a return flight. flightSearchDataModel.InboundFlights = null; } }
public void VerifyUserIsAbleToSearchForAFlightWithAdditionalValidInfo() { FlightSearchDataModel flightSearchDataModel = new FlightSearchDataModel { Origin = AirportsStartsWithA.Abadan, Destination = AirportsStartsWithC.ColomboBandaranaikeInternationalAirport, DateFrom = LocalToday.AddMonths(2).AsLocalDate(), DateTo = LocalToday.AddMonths(3).AddDays(10).AsLocalDate(), TripType = TripTypes.Return, Travelers = new TravelersAboveForm { Adults = 2, Children = 1, InfantOnLap = 1 }, CabinClass = CabinClasses.First, Baggage = new Baggage { CabinBag = 1, CheckedBag = 2 } }; That.Given(_ => BaseUiSteps.IClickOnPrivacyPopupWindowAction(PrivacyPopupWindowActions.Accept)) .And(_ => BaseUiSteps.INavigateToPage(PageUriFields.Flights)) .When(_ => FlightSearchUiSteps.IFillAdditionalTravelInfoSection(flightSearchDataModel)) .When(_ => FlightSearchUiSteps.IClickOnOriginPanel()) .And(_ => FlightSearchUiSteps.ISelectOriginFromDropdown(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnDestinationPanel()) .And(_ => FlightSearchUiSteps.ISelectDestinationFromDropdown(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnDepartureDateInput()) .And(_ => FlightSearchUiSteps.IEnterDepartureDate(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnReturnDateInput()) .And(_ => FlightSearchUiSteps.IEnterReturnDate(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickSearchFlightsButton()) .Then(_ => FlightSearchResultUiSteps.IShouldSeeTheFlightResultSection()) .BDDfy("Verify user is able to search for a flight with additional valid info"); }
public void VerifyUserIsAbleToSearchForAFlightWithValidInfo() { FlightSearchDataModel flightSearchDataModel = new FlightSearchDataModel { Origin = AirportsStartsWithA.Abadan, Destination = AirportsStartsWithC.ColomboBandaranaikeInternationalAirport, DateFrom = LocalToday.AddMonths(1).AsLocalDate(), DateTo = LocalToday.AddMonths(4).AddDays(10).AsLocalDate() }; That.Given(_ => BaseUiSteps.IClickOnPrivacyPopupWindowAction(PrivacyPopupWindowActions.Accept)) .And(_ => BaseUiSteps.INavigateToPage(PageUriFields.Flights)) .When(_ => FlightSearchUiSteps.IClickOnOriginPanel()) .And(_ => FlightSearchUiSteps.ISelectOriginFromDropdown(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnDestinationPanel()) .And(_ => FlightSearchUiSteps.ISelectDestinationFromDropdown(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnDepartureDateInput()) .And(_ => FlightSearchUiSteps.IEnterDepartureDate(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickOnReturnDateInput()) .And(_ => FlightSearchUiSteps.IEnterReturnDate(flightSearchDataModel)) .And(_ => FlightSearchUiSteps.IClickSearchFlightsButton()) .Then(_ => FlightSearchResultUiSteps.IShouldSeeTheFlightResultSection()) .BDDfy("Verify user is able to search for a flight with valid info"); }
public void FillAdditionalTravelInfo(FlightSearchDataModel additionalInfo) { _map.Value.FillAdditionalTravelInfo(additionalInfo); }
public void EnterReturnDate(FlightSearchDataModel flightSearchDataModel) { _map.Value.EnterReturnDate(flightSearchDataModel.DateTo); }
public void EnterDepartureDate(FlightSearchDataModel flightSearchDataModel) { _map.Value.EnterDepartureDate(flightSearchDataModel.DateFrom); }
public void SelectDestinationFromDropdown(FlightSearchDataModel flightSearchDataModel) { _map.Value.SelectDestinationOption(flightSearchDataModel.Destination); }
public void SelectOriginFromDropdown(FlightSearchDataModel flightSearchDataModel) { _map.Value.FlightOriginInput.SelectOption(flightSearchDataModel.Origin); }
public void IEnterReturnDate(FlightSearchDataModel date) { PageFactory.GetPage <FlightSearchPage>().EnterReturnDate(date); }
public void IFillAdditionalTravelInfoSection(FlightSearchDataModel additionalInfo) { PageFactory.GetPage <FlightSearchPage>().FillAdditionalTravelInfo(additionalInfo); }
private void SelectTripType(FlightSearchDataModel additionalInfo) { TripTypes.Click(); FindElement(string.Format(TripTypeOption, additionalInfo.TripType)).Click(); }
private void SelectCabinClass(FlightSearchDataModel additionalInfo) { CabinClass.Click(); FindElement(string.Format(CabinClassOption, additionalInfo.CabinClass)).Click(); }