Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            SetupAirlineData();

            string command;

            do
            {
                System.Console.WriteLine("Please enter command.");
                command = System.Console.ReadLine() ?? "";
                var enteredText = command.ToLower();
                if (enteredText.Contains("print summary"))
                {
                    System.Console.WriteLine();
                    System.Console.WriteLine(_scheduledFlight.GetSummary());
                }
                else if (enteredText.Contains("add general"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new Passenger
                    {
                        Type = PassengerType.General,
                        Name = passengerSegments[2],
                        Age  = Convert.ToInt32(passengerSegments[3])
                    });
                }
                else if (enteredText.Contains("add loyalty"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new Passenger
                    {
                        Type                 = PassengerType.LoyaltyMember,
                        Name                 = passengerSegments[2],
                        Age                  = Convert.ToInt32(passengerSegments[3]),
                        LoyaltyPoints        = Convert.ToInt32(passengerSegments[4]),
                        IsUsingLoyaltyPoints = Convert.ToBoolean(passengerSegments[5]),
                    });
                }
                else if (enteredText.Contains("add airline"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new Passenger
                    {
                        Type = PassengerType.AirlineEmployee,
                        Name = passengerSegments[2],
                        Age  = Convert.ToInt32(passengerSegments[3]),
                    });
                }
                else if (enteredText.Contains("exit"))
                {
                    Environment.Exit(1);
                }
                else
                {
                    System.Console.ForegroundColor = ConsoleColor.Red;
                    System.Console.WriteLine("UNKNOWN INPUT");
                    System.Console.ResetColor();
                }
            } while (command != "exit");
        }
Ejemplo n.º 2
0
        public void Should_Choose_Bigger_Airplane()
        {
            var passengerService = new PassengerService();
            var aircraftService  = new AircraftService();

            aircraftService
            .AddPlanes(TestData.SmallAntonovPlane,
                       TestData.BombardierPlane,
                       TestData.ATRPlane);
            var calculationService = new CalculationService();

            calculationService.AddRules(new ProfitRule(), new RelaxedRule());
            var flightService   = new FlightService(TestData.LondonToParis);
            var scheduledFlight = new ScheduledFlight(
                flightService,
                passengerService,
                aircraftService,
                calculationService,
                new SummaryFormat(passengerService, aircraftService));

            scheduledFlight.SetAircraftForRoute(122);
            scheduledFlight.SetCurrentRule <ProfitRule>();

            scheduledFlight.AddPassenger(TestData.SteveGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.MarkGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.JamesGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.JaneGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.AlanGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.SuzyGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.AnthonyGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.MikeGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.JohnLoyaltyPassenger);
            scheduledFlight.AddPassenger(TestData.SarahLoyaltyPassenger);
            scheduledFlight.AddPassenger(TestData.JackLoyaltyPassenger);
            scheduledFlight.AddPassenger(TestData.TrevorAirlineEmployeePassenger);

            scheduledFlight.Process();
            _output.WriteLine(scheduledFlight.GetSummary());

            Assert.Equal(12, passengerService.GetCountForPassengerType <Passenger>());
            Assert.Equal(8, passengerService.GetCountForPassengerType <GeneralPassenger>());
            Assert.Equal(3, passengerService.GetCountForPassengerType <LoyaltyPassenger>());
            Assert.Equal(1, passengerService.GetCountForPassengerType <AirlineEmployeePassenger>());

            Assert.Equal(15, flightService.TotalExpectedBaggage);
            Assert.Equal(1000, flightService.ProfitFromFlight);
            Assert.Equal(600, flightService.CostOfFlight);
            Assert.Equal(10, flightService.TotalLoyaltyPointsAccrued);
            Assert.Equal(100, flightService.TotalLoyaltyPointsRedeemed);
            Assert.Equal(400, flightService.ProfitSurplus);
            Assert.Equal(
                @"Flight summary for London to Paris

Total passengers: 12
    General sales: 8
    Loyalty member sales: 3
    Airline employee comps: 1

Total expected baggage: 15

Total revenue from flight: 1000
Total costs from flight: 600
Flight generating profit of: 400

Total loyalty points given away: 10
Total loyalty points redeemed: 100


FLIGHT MAY NOT PROCEED
Other more suitable aircraft are:
Bombardier Q400 could handle this flight
ATR 640 could handle this flight
",
                scheduledFlight.GetSummary());
        }
Ejemplo n.º 3
0
        public void Ensure_That_Original_Use_Case_Works()
        {
            var passengerService = new PassengerService();
            var aircraftService  = new AircraftService();

            aircraftService.AddPlanes(TestData.AntonovPlane);
            var calculationService = new CalculationService();

            calculationService.AddRules(new ProfitRule(), new RelaxedRule());
            var flightService   = new FlightService(TestData.LondonToParis);
            var scheduledFlight = new ScheduledFlight(
                flightService,
                passengerService,
                aircraftService,
                calculationService,
                new SummaryFormat(passengerService, aircraftService));

            scheduledFlight.SetAircraftForRoute(123);
            scheduledFlight.SetCurrentRule <ProfitRule>();

            scheduledFlight.AddPassenger(TestData.SteveGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.MarkGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.JamesGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.JaneGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.AlanGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.SuzyGeneralPassenger);
            scheduledFlight.AddPassenger(TestData.JohnLoyaltyPassenger);
            scheduledFlight.AddPassenger(TestData.SarahLoyaltyPassenger);
            scheduledFlight.AddPassenger(TestData.JackLoyaltyPassenger);
            scheduledFlight.AddPassenger(TestData.TrevorAirlineEmployeePassenger);

            scheduledFlight.Process();


            Assert.Equal(10, passengerService.GetCountForPassengerType <Passenger>());
            Assert.Equal(6, passengerService.GetCountForPassengerType <GeneralPassenger>());
            Assert.Equal(3, passengerService.GetCountForPassengerType <LoyaltyPassenger>());
            Assert.Equal(1, passengerService.GetCountForPassengerType <AirlineEmployeePassenger>());

            Assert.Equal(13, flightService.TotalExpectedBaggage);
            Assert.Equal(800, flightService.ProfitFromFlight);
            Assert.Equal(500, flightService.CostOfFlight);
            Assert.Equal(10, flightService.TotalLoyaltyPointsAccrued);
            Assert.Equal(100, flightService.TotalLoyaltyPointsRedeemed);
            Assert.Equal(300, flightService.ProfitSurplus);
            Assert.Equal(
                @"Flight summary for London to Paris

Total passengers: 10
    General sales: 6
    Loyalty member sales: 3
    Airline employee comps: 1

Total expected baggage: 13

Total revenue from flight: 800
Total costs from flight: 500
Flight generating profit of: 300

Total loyalty points given away: 10
Total loyalty points redeemed: 100


THIS FLIGHT MAY PROCEED",
                scheduledFlight.GetSummary());
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                Setup();

                using (var file = new StreamReader(@"commands.txt"))
                {
                    var command = "";

                    do
                    {
                        command = file.ReadLine() ?? "";
                        var enteredText = command.ToLower();
                        if (enteredText.Contains("print summary"))
                        {
                            Console.WriteLine();
                            var summarySegments = enteredText.Split(' ');
                            if (summarySegments.Length > 2 && summarySegments[2] == "relaxed")
                            {
                                Console.WriteLine(_scheduledFlight.GetSummary(RuleSetType.Relaxed));
                            }
                            else
                            {
                                Console.WriteLine(_scheduledFlight.GetSummary(RuleSetType.Default));
                            }
                        }
                        else if (enteredText.Contains("add general"))
                        {
                            var passengerSegments = enteredText.Split(' ');
                            _scheduledFlight.AddPassenger(
                                PassengerHelper.CreateGeneral(
                                    passengerSegments[2],
                                    Convert.ToInt32(passengerSegments[3])));
                        }
                        else if (enteredText.Contains("add loyalty"))
                        {
                            var passengerSegments = enteredText.Split(' ');
                            _scheduledFlight.AddPassenger(
                                PassengerHelper.CreateLoyaltyMember(
                                    passengerSegments[2],
                                    Convert.ToInt32(passengerSegments[3]),
                                    Convert.ToInt32(passengerSegments[4]),
                                    Convert.ToBoolean(passengerSegments[5])));
                        }
                        else if (enteredText.Contains("add airline"))
                        {
                            var passengerSegments = enteredText.Split(' ');
                            _scheduledFlight.AddPassenger(
                                PassengerHelper.CreateAirlineEmployee(
                                    passengerSegments[2],
                                    Convert.ToInt32(passengerSegments[3])));
                        }
                        else if (enteredText.Contains("add discounted"))
                        {
                            var passengerSegments = enteredText.Split(' ');
                            _scheduledFlight.AddPassenger(
                                PassengerHelper.CreateDiscounted(
                                    passengerSegments[2],
                                    Convert.ToInt32(passengerSegments[3])));
                        }
                        else if (enteredText.Contains("exit"))
                        {
#if DEBUG
                            Console.ReadKey();
#endif
                            Environment.Exit(1);
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("UNKNOWN INPUT");
                            Console.ResetColor();
                        }
                    } while (command != "exit");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
#if DEBUG
                Console.ReadKey();
#endif
            }
        }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            SetupAirlineData();

            string command;

            do
            {
                System.Console.WriteLine("Please enter command.");
                command = System.Console.ReadLine() ?? "";
                var enteredText = command.ToLower();
                if (enteredText.Contains("print summary"))
                {
                    System.Console.WriteLine();
                    System.Console.WriteLine(_scheduledFlight.GetSummary());
                }
                else if (enteredText.Contains("add general"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new General
                    {
                        Name = passengerSegments[2],
                        Age  = Convert.ToInt32(passengerSegments[3])
                    });
                }
                else if (enteredText.Contains("add loyalty"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new Loyalty
                    {
                        Name                 = passengerSegments[2],
                        Age                  = Convert.ToInt32(passengerSegments[3]),
                        LoyaltyPoints        = Convert.ToInt32(passengerSegments[4]),
                        IsUsingLoyaltyPoints = Convert.ToBoolean(passengerSegments[5]),
                    });
                }
                else if (enteredText.Contains("add airline"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new Airline
                    {
                        Name = passengerSegments[2],
                        Age  = Convert.ToInt32(passengerSegments[3]),
                    });
                }
                else if (enteredText.Contains("add discounted"))
                {
                    var passengerSegments = enteredText.Split(' ');
                    _scheduledFlight.AddPassenger(new Discounted
                    {
                        Name = passengerSegments[2],
                        Age  = Convert.ToInt32(passengerSegments[3]),
                    });
                }
                else if (enteredText.Contains("ruleset relaxed"))
                {
                    var segments = enteredText.Split(' ');
                    _scheduledFlight.RuleSet = new RelaxedRuleSet();
                }
                else if (enteredText.Contains("ruleset default"))
                {
                    var segments = enteredText.Split(' ');
                    _scheduledFlight.RuleSet = new DefaultRuleSet();
                }
                else if (enteredText.Contains("exit"))
                {
                    Environment.Exit(1);
                }
                else
                {
                    System.Console.ForegroundColor = ConsoleColor.Red;
                    System.Console.WriteLine("UNKNOWN INPUT");
                    System.Console.ResetColor();
                }
            } while (command != "exit");
        }