public void When_Relaxed_Rule_Is_Used_Should_Proceed_With_Flight() { var passengerService = new PassengerService(); var aircraftService = new AircraftService(); aircraftService.AddPlanes(TestData.SmallAntonovPlane); 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 <RelaxedRule>(); scheduledFlight.AddPassenger(TestData.JackLoyaltyPassenger); scheduledFlight.AddPassenger(TestData.TrevorAirlineEmployeePassenger); scheduledFlight.AddPassenger(TestData.SunnyAirlineEmployeePassenger); scheduledFlight.AddPassenger(TestData.SunnyAirlineEmployeePassenger); scheduledFlight.AddPassenger(TestData.MartinAirlineEmployeePassenger); scheduledFlight.AddPassenger(TestData.MartinAirlineEmployeePassenger); scheduledFlight.AddPassenger(TestData.MikeDiscountedPassenger); scheduledFlight.Process(); Assert.True(flightService.CanFlightProceed); Assert.Equal(-200, flightService.ProfitSurplus); }
private static void SetupAirlineData() { _flightRuleService = new FlightRuleService(); _availablePlaneService = new AvailablePlaneService(); _availablePlaneService.Planes = new List <Plane>(); _availablePlaneService.Planes.Add(new Plane { Id = 124, Name = "Bombardier Q400", NumberOfSeats = 15 }); _availablePlaneService.Planes.Add(new Plane { Id = 125, Name = "ATR 640", NumberOfSeats = 20 }); var londonToParis = new FlightRoute("London", "Paris") { BaseCost = 50, BasePrice = 100, LoyaltyPointsGained = 5, MinimumTakeOffPercentage = 0.7 }; _scheduledFlight = new ScheduledFlight( londonToParis, _flightRuleService, _availablePlaneService); _scheduledFlight.SetAircraftForRoute(new Plane { Id = 123, Name = "Antonov AN-2", NumberOfSeats = 12 }); }
private static void SetupAirlineData(List <IFlightBusinessRule> flightBusinessRule) { var londonToParis = new FlightRoute("London", "Paris") { BaseCost = 50, BasePrice = 100, LoyaltyPointsGained = 5, MinimumTakeOffPercentage = 0.1 }; var availablePlanes = new List <Plane> { new Plane { Id = 234, Name = "Bombardier Q400", NumberOfSeats = 250 }, new Plane { Id = 345, Name = "Airbus A340", NumberOfSeats = 200 } }; _scheduledFlight = new ScheduledFlight(londonToParis, flightBusinessRule, availablePlanes); _scheduledFlight.SetAircraftForRoute(new Plane { Id = 123, Name = "Antonov AN-2", NumberOfSeats = 12 }); }
public void Minimum_Percentage_Not_Exceeded() { List <Plane> planes = new List <Plane>(); planes.Add(new Plane { Id = 123, Name = "Golden C3P-O", NumberOfSeats = 6 }); planes.Add(new Plane { Id = 124, Name = "Stormtrooper FN-11", NumberOfSeats = 8 }); var madridToPrague = new FlightRoute("Madrid", "Prague") { BaseCost = 80, BasePrice = 150, LoyaltyPointsGained = 10, MinimumTakeOffPercentage = 0.5 }; var scheduledFlight = new ScheduledFlight(madridToPrague); scheduledFlight.SetAircraftForRoute(planes[0]); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.General, Name = "George", Age = 23, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.General, Name = "Steph", Age = 25, AllowedBags = 1 }); var seatsTaken = scheduledFlight.Passengers.Count(); Assert.False(scheduledFlight.CheckMinPercentageExceeded(seatsTaken)); }
public void Check_Seat_Availability() { List <Plane> planes = new List <Plane>(); planes.Add(new Plane { Id = 123, Name = "Golden C3P-O", NumberOfSeats = 3 }); planes.Add(new Plane { Id = 124, Name = "Stormtrooper FN-11", NumberOfSeats = 5 }); var madridToPrague = new FlightRoute("Madrid", "Prague") { BaseCost = 80, BasePrice = 150, LoyaltyPointsGained = 10, MinimumTakeOffPercentage = 0.5 }; var scheduledFlight = new ScheduledFlight(madridToPrague); scheduledFlight.SetAircraftForRoute(planes[0]); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.General, Name = "George", Age = 23, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.LoyaltyMember, Name = "Luke", Age = 33, LoyaltyPoints = 1500, IsUsingLoyaltyPoints = true, AllowedBags = 2 }); var seatsTaken = scheduledFlight.Passengers.Count(); Assert.True(scheduledFlight.CheckSeatsTaken(seatsTaken, planes)); }
public void Should_Return_Same_Data_When_Calling_Process_Twice() { 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.AnthonyGeneralPassenger); scheduledFlight.AddPassenger(TestData.MikeGeneralPassenger); scheduledFlight.AddPassenger(TestData.JohnLoyaltyPassenger); scheduledFlight.AddPassenger(TestData.SarahLoyaltyPassenger); scheduledFlight.AddPassenger(TestData.JackLoyaltyPassenger); scheduledFlight.AddPassenger(TestData.TrevorAirlineEmployeePassenger); scheduledFlight.AddPassenger(TestData.MikeDiscountedPassenger); scheduledFlight.Process(); scheduledFlight.Process(); Assert.Equal(13, passengerService.GetCountForPassengerType <Passenger>()); Assert.Equal(8, passengerService.GetCountForPassengerType <GeneralPassenger>()); Assert.Equal(3, passengerService.GetCountForPassengerType <LoyaltyPassenger>()); Assert.Equal(1, passengerService.GetCountForPassengerType <DiscountedPassenger>()); Assert.Equal(1, passengerService.GetCountForPassengerType <AirlineEmployeePassenger>()); Assert.Equal(15, flightService.TotalExpectedBaggage); Assert.Equal(1050, flightService.ProfitFromFlight); Assert.Equal(650, flightService.CostOfFlight); Assert.Equal(10, flightService.TotalLoyaltyPointsAccrued); Assert.Equal(100, flightService.TotalLoyaltyPointsRedeemed); Assert.Equal(400, flightService.ProfitSurplus); }
private static void SetupAirlineData() { var londonToParis = new FlightRoute("London", "Paris") { BaseCost = 50, BasePrice = 100, LoyaltyPointsGained = 5, MinimumTakeOffPercentage = 0.7 }; _scheduledFlight = new ScheduledFlight(londonToParis); _scheduledFlight.SetAircraftForRoute(_planes[0]); }
public void Profit_Surplus_Is_Negative_But_Airline_Employees_Exceed_Minimum_Percentage() { var madridToPrague = new FlightRoute("Madrid", "Prague") { BaseCost = 80, BasePrice = 150, LoyaltyPointsGained = 10, MinimumTakeOffPercentage = 0.3 }; var scheduledFlight = new ScheduledFlight(madridToPrague); scheduledFlight.SetAircraftForRoute(new Plane { Id = 124, Name = "Vader Darth-87", NumberOfSeats = 10 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.AirlineEmployee, Name = "John", Age = 32, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.AirlineEmployee, Name = "Jen", Age = 28, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.AirlineEmployee, Name = "Tom", Age = 47, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.LoyaltyMember, Name = "Mike", Age = 26, LoyaltyPoints = 1500, IsUsingLoyaltyPoints = true, AllowedBags = 2 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.LoyaltyMember, Name = "Pan", Age = 56, LoyaltyPoints = 500, IsUsingLoyaltyPoints = false, AllowedBags = 2 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.AirlineEmployee, Name = "Natalie", Age = 30, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.Discounted, Name = "Chris", Age = 38, AllowedBags = 0 }); var costOfFlight = scheduledFlight.Passengers.Count * madridToPrague.BaseCost; var totalPriceForGeneral = scheduledFlight.Passengers.Where(p => p.Type == PassengerType.General).Count() * madridToPrague.BasePrice; var totalPriceForNonUsingLoyaltyPoints = scheduledFlight.Passengers.Where(p => p.Type == PassengerType.LoyaltyMember && p.IsUsingLoyaltyPoints == false).Count() * madridToPrague.BasePrice; var totalPriceForDiscounted = (scheduledFlight.Passengers.Where(p => p.Type == PassengerType.Discounted).Count() * madridToPrague.BasePrice) / 2; var profitFromFlight = (totalPriceForGeneral + totalPriceForNonUsingLoyaltyPoints + totalPriceForDiscounted) - costOfFlight; var seatsTaken = scheduledFlight.Passengers.Count(); Assert.True(scheduledFlight.CheckProfitSurplus(profitFromFlight)); }
private static void SetupAirlineData() { var londonToParis = new FlightRoute("London", "Paris") { BaseCost = 50, BasePrice = 100, LoyaltyPointsGained = 5, MinimumTakeOffPercentage = 0.7 }; _scheduledFlight = new ScheduledFlight(londonToParis); _scheduledFlight.SetAircraftForRoute(new Plane { Id = 123, Name = "Antonov AN-2", NumberOfSeats = 12 }); }
private static void Setup() { var londonToParis = new FlightRoute("London", "Paris") { BaseCost = 50, BasePrice = 100, LoyaltyPointsGained = 5, MinimumTakeOffPercentage = 0.7 }; _scheduledFlight = new ScheduledFlight( londonToParis, Container.GetInstance <ISummaryBuilder>(), Container.GetInstance <ISummaryOutputGenerator>(), Container.GetInstance <IFleetRepository>()); _scheduledFlight.SetAircraftForRoute(123); }
public void Calculate_Loyalty_Points() { var madridToPrague = new FlightRoute("Madrid", "Prague") { BaseCost = 80, BasePrice = 150, LoyaltyPointsGained = 10, MinimumTakeOffPercentage = 0.5 }; var scheduledFlight = new ScheduledFlight(madridToPrague); scheduledFlight.SetAircraftForRoute(new Plane { Id = 124, Name = "Vader Darth-87", NumberOfSeats = 10 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.General, Name = "John", Age = 32, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.General, Name = "Jen", Age = 28, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.General, Name = "Tom", Age = 47, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.LoyaltyMember, Name = "Mike", Age = 26, LoyaltyPoints = 1500, IsUsingLoyaltyPoints = true, AllowedBags = 2 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.LoyaltyMember, Name = "Pan", Age = 56, LoyaltyPoints = 500, IsUsingLoyaltyPoints = false, AllowedBags = 2 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.AirlineEmployee, Name = "Natalie", Age = 30, AllowedBags = 1 }); scheduledFlight.Passengers.Add(new Passenger { Type = PassengerType.Discounted, Name = "Chris", Age = 38, AllowedBags = 0 }); var totalLoyaltyPointsAccrued = scheduledFlight.Passengers.Where(p => p.Type == PassengerType.LoyaltyMember && p.IsUsingLoyaltyPoints == false).Count() * madridToPrague.LoyaltyPointsGained; var totalLoyaltyPointsRedeemed = scheduledFlight.Passengers.Where(p => p.Type == PassengerType.LoyaltyMember && p.IsUsingLoyaltyPoints == true).Count() * madridToPrague.BasePrice;; Assert.Equal(10, totalLoyaltyPointsAccrued); Assert.Equal(150, totalLoyaltyPointsRedeemed); }
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()); }
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()); }