public async Task Confirm(object o) { if (!ValidateConfirm()) { return; } try { UiState = UiState.Wait; await m_crudManager.AddRoute(SelectedAirline.IataAirlineCode, SelectedOrigin.IataAirportCode, SelectedDestination.IataAirportCode, FlightDurations.ToList(), ClassPricingSchemes.ToList()); UiState = UiState.Normal; MessageBoxResult result = MessageBox.Show("Route added successfully. Add another?", "Success", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { m_pageController.AddRoute(); } else { m_pageController.Home(); } } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message, "Error"); } }
public void AddRouteTest() { using (FlightReservationContext db = new FlightReservationContext()) { List <ClassPricingScheme> pricingScheme = new List <ClassPricingScheme> { new ClassPricingScheme { TravelClassCode = "E", TravelClassName = "Economy Class", AdultFare = 200, ChildFare = 160, InfantFare = 40 }, new ClassPricingScheme { TravelClassCode = "B", TravelClassName = "Business Class", AdultFare = 1000, ChildFare = 800, InfantFare = 200 } }; List <FlightDuration> flightDurations = new List <FlightDuration> { new FlightDuration { Aircraft = new AircraftInfo { IcaoTypeCode = "A320", Model = "Airbus A320" }, DurationHours = 1, DurationMinutes = 45 }, new FlightDuration { Aircraft = new AircraftInfo { IcaoTypeCode = "B733", Model = "Boeing 737-300" }, DurationHours = 1, DurationMinutes = 50 } }; m_crudManager.AddRoute("BA", "BHX", "ARN", flightDurations, pricingScheme); var routeQuery = from r in db.Route where r.AirlineCode == "BA" && r.OriginAirportCode == "BHX" && r.DestinationAirportCode == "ARN" select r; Assert.DoesNotThrow(() => routeQuery.Single()); Route selectedRoute = routeQuery.Single(); List <ClassPricingScheme> selectedRoutePricingScheme = JsonConvert.DeserializeObject <List <ClassPricingScheme> >(selectedRoute.PricingScheme); Assert.AreEqual(2, selectedRoutePricingScheme.Count); Assert.AreEqual("E", selectedRoutePricingScheme[0].TravelClassCode); Assert.AreEqual(200, selectedRoutePricingScheme[0].AdultFare); Assert.AreEqual(160, selectedRoutePricingScheme[0].ChildFare); Assert.AreEqual(40, selectedRoutePricingScheme[0].InfantFare); Assert.AreEqual("B", selectedRoutePricingScheme[1].TravelClassCode); Assert.AreEqual(1000, selectedRoutePricingScheme[1].AdultFare); Assert.AreEqual(800, selectedRoutePricingScheme[1].ChildFare); Assert.AreEqual(200, selectedRoutePricingScheme[1].InfantFare); var routeAircraftQuery = from r in db.Route join ra in db.RouteAircraft on r.RouteId equals ra.RouteId where r.AirlineCode == "BA" && r.OriginAirportCode == "BHX" && r.DestinationAirportCode == "ARN" select ra; List <RouteAircraft> selectedRouteAircraft = routeAircraftQuery.ToList(); Assert.AreEqual(2, selectedRouteAircraft.Count); Assert.IsTrue(selectedRouteAircraft.Exists(ra => ra.IcaoTypeCode == "A320" && ra.FlightDuration == 105)); Assert.IsTrue(selectedRouteAircraft.Exists(ra => ra.IcaoTypeCode == "B733" && ra.FlightDuration == 110)); db.RouteAircraft.RemoveRange(selectedRouteAircraft); db.Route.Remove(selectedRoute); db.SaveChanges(); } }