public void Constuctor_GeneralPassenger_ShouldSetProperties() { var passenger = new GeneralPassenger("john", 33, "airline"); Assert.AreEqual("john", passenger.FirstName); Assert.AreEqual(33, passenger.Age); PassengerType ptype; Assert.AreEqual(true, Enum.TryParse <PassengerType>("airline", true, out ptype)); }
private void ParseFlightReportLine(string line, FlightReport flightReport) { var instructionLine = GetInstructionLine(line); if (flightReport.Route == null) // Route must be set first { if (instructionLine.Type != InstructionLineType.AddRoute) { throw new Exception("Route is not set."); } flightReport.Route = new Route(instructionLine.ParametersArray); } else if (flightReport.Aircraft == null) // Aircraft must be set first { if (instructionLine.Type != InstructionLineType.AddAircraft) { throw new Exception("Aircraft is not set."); } flightReport.Aircraft = new Aircraft(instructionLine.ParametersArray); } else // Parse passengers { Passenger passenger = null; switch (instructionLine.Type) { case InstructionLineType.AddRoute: // Route must be set only once throw new Exception("Route is already set."); case InstructionLineType.AddAircraft: // Aircraft must be set only once throw new Exception("Aircraft is already set."); case InstructionLineType.AddGeneralPassenger: passenger = new GeneralPassenger(instructionLine.ParametersArray); break; case InstructionLineType.AddLoyaltyPassenger: passenger = new LoyaltyPassenger(instructionLine.ParametersArray); break; case InstructionLineType.AddAirlinePassenger: passenger = new AirlinePassenger(instructionLine.ParametersArray); break; } if (passenger == null) { throw new Exception("Passengers are not set."); } flightReport.Passengers.Add(passenger); } }
public override void Display() { base.Display(); var passengerName = Input.ReadString("Enter general passenger name: "); var passengerAge = Input.ReadInt("Enter general passenger age: ", 1, 120); var passenger = new GeneralPassenger() { Name = passengerName, Age = passengerAge }; FlightProgram.ScheduledFlight.AddPassenger(passenger); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateHome(); }
/// <summary> /// Passenger Factory method. /// Initializes instance of Passenger Class. /// </summary> /// <param name="passengerId"></param> /// <param name="isUsingLoyalty"></param> /// <param name="LoyaltyPoints"></param> /// <param name="hasExtraBags"></param> /// <returns></returns> private static IPassengerDetails GetPassengerType(string passengerId, bool isUsingLoyalty, int LoyaltyPoints, bool hasExtraBags) { IPassengerDetails passenger; switch (passengerId) { case "airline": passenger = new AirlineEmployee(new FlightSummaryValidator()); break; case "general": passenger = new GeneralPassenger(new FlightSummaryValidator()); break; case "loyalty": passenger = new LoyaltyMember(new LoyaltyBenefits(isUsingLoyalty, LoyaltyPoints, hasExtraBags), new FlightSummaryValidator()); break; default: throw new Exception(); } return(passenger); }
public void InValid_PassengerType_ArgumentOutOfRangeException() { var passenger = new GeneralPassenger("john", 33, "normal"); }
public void Setup() { _iPassengerDetails = Substitute.For <IPassengerDetails>(); _generalPassenger = new GeneralPassenger(new FlightSummaryValidator()); }
public override void Display() { base.Display(); string command; do { System.Console.WriteLine("Please enter command."); command = System.Console.ReadLine() ?? ""; try { var enteredText = command.ToLower(); if (enteredText.Contains("add general")) { var passengerSegments = enteredText.Split(' '); var generalPassenger = new GeneralPassenger { Name = passengerSegments[2], Age = Convert.ToInt32(passengerSegments[3]) }; FlightProgram.ScheduledFlight.AddPassenger(generalPassenger); } else if (enteredText.Contains("add loyalty")) { var passengerSegments = enteredText.Split(' '); var loyaltyPassenger = new LoyaltyPassenger { Name = passengerSegments[2], Age = Convert.ToInt32(passengerSegments[3]), TotalPoints = Convert.ToInt32(passengerSegments[4]), UsePoints = Convert.ToBoolean(passengerSegments[5]) }; FlightProgram.ScheduledFlight.AddPassenger(loyaltyPassenger); } else if (enteredText.Contains("add airline")) { var passengerSegments = enteredText.Split(' '); var airlineEmployee = new AirlineEmployee { Name = passengerSegments[2], Age = Convert.ToInt32(passengerSegments[3]) }; FlightProgram.ScheduledFlight.AddPassenger(airlineEmployee); } else if (enteredText.Contains("add discount")) { var passengerSegments = enteredText.Split(' '); var discountEmployee = new DiscountedPassenger { Name = passengerSegments[2], Age = Convert.ToInt32(passengerSegments[3]) }; FlightProgram.ScheduledFlight.AddPassenger(discountEmployee); } else if (enteredText.Contains("display summary")) { Program.NavigateTo <DisplaySummaryPage>(); } } catch { Output.WriteLine("Input format was not in a correct format. Please try again."); } } while (command != "exit"); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateHome(); }