public FlightCollection(IFlightCalculator flightCalculator, IFlightFilter flightFilter, ICollisionDetector collisionDetector) { flightFilter.transponderFilterChanged += GetTransponderData; this.FlightList = new List <Flight>(); this.flightCalculator = flightCalculator; this.collisionDetector_ = collisionDetector; }
public void SetUp() { fakeReceiver = Substitute.For <ITransponderReceiver>(); fakeFilter = Substitute.For <IFlightFilter>(); uut = new DataFormatter(fakeReceiver); }
public void SetUp() { //arrange stubCalculator = new StubCalculator(); stubFilter = Substitute.For <IFlightFilter>(); stubCollisionDetector = Substitute.For <ICollisionDetector>(); uut = new FlightCollection(stubCalculator, stubFilter, stubCollisionDetector); receivedArgs = null; setArgs = new FlightArgs(); setArgs.flights = new List <Flight>(); TransponderData td = new TransponderData("aaa", 0, 0, 0, new DateTime()); Flight f = new Flight(td); stubCollisionDetector.OnFlightsChanged(Arg.Any <FlightArgs>()).ReturnsForAnyArgs(setArgs.flights); numberOfFlightsChangedEvents = 0; uut.flightsChanged += (s, e) => { receivedArgs = e; numberOfFlightsChangedEvents++; }; }
static void Main(string[] args) { string isRepeat = string.Empty; do { try { Console.WriteLine("Please select the search Categary:"); Console.WriteLine("0. Print all flights"); Console.WriteLine("1. Depart before the current date/time."); Console.WriteLine("2. Have a segment with an arrival date before the departure date."); Console.WriteLine("3. Spend more than [X] hours on the ground."); Console.WriteLine("Press e for end"); Console.WriteLine("--------------------------------------------------------------"); MyDependancyResolver myDependancyResolver = new MyDependancyResolver(); IFlightBuilder flightBuilder = (IFlightBuilder)myDependancyResolver.GetConcreteClass(typeof(IFlightBuilder)); IFlightFilter flightFilter = null; IList <Flight> flight = null; string input = Console.ReadLine(); switch (input) { case "3": case "2": case "1": case "0": flightFilter = myDependancyResolver.GetFlightFilterImplementation(input, flightBuilder); if (flightFilter.ParameterCount > 0) { Console.WriteLine("X value:"); flightFilter.ParameterArray = new object[] { Console.ReadLine() }; } break; case "e": isRepeat = "true"; break; default: Console.WriteLine(ValidationString); break; } if (flightFilter != null) { flight = flightFilter.GetFilterResult(); IFlightPrinter printFlight = (IFlightPrinter)myDependancyResolver.GetConcreteClass(typeof(IFlightPrinter)); printFlight.PrintFlights(flight); } } catch (Exception) { Console.WriteLine(SearchAgainString); isRepeat = "true"; continue; } } while (string.IsNullOrEmpty(isRepeat)); }
private static void Main(string[] args) { var filterCase1 = new IFlightFilter[] { new BeforeNowDepartureFlightFilter() }; var filterCase2 = new IFlightFilter[] { new ArrivalBeforeDepartureFilter() }; var filterCase3 = new IFlightFilter[] { new TwoHoursDelayFilter() }; var filterExtraCase = new IFlightFilter[] { new BeforeNowDepartureFlightFilter(), new ArrivalBeforeDepartureFilter(), new TwoHoursDelayFilter() }; var flightBuilder = new FlightBuilder(); var flights = flightBuilder.GetFlights(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nBeforeNowDepartureFlightFilter Results:"); Console.ResetColor(); foreach (var flight in flights.Filter(filterCase1)) { flight.DisplayInfo(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nArrivalBeforeDepartureFilter Results:"); Console.ResetColor(); foreach (var flight in flights.Filter(filterCase2)) { flight.DisplayInfo(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nTwoHoursDelayFilter Results:"); Console.ResetColor(); foreach (var flight in flights.Filter(filterCase3)) { flight.DisplayInfo(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nAll Filters Results:"); Console.ResetColor(); foreach (var flight in flights.Filter(filterExtraCase)) { flight.DisplayInfo(); } }
public void Begin() { flightFilter = new ConsoleFlightFilter(db); string inp = ""; bool done = false; IList <Flight <int> > flights = new List <Flight <int> >(); while (!done) { PrintMenu(); inp = Console.ReadLine(); switch (inp.Trim()) { case "q": done = true; break; case "1": flights = flightFilter.Filter(db.FlightDao.GetAll()); ShowFlights(flights); break; case "2": MenuDelayFlight(); break; case "3": MenuChangeBookingDeadline(); break; case "4": MenuShowSoldTickets(); break; case "5": foreach (Ticket <int> t in db.TicketDao.GetAll()) { PrinTicket(t); } break; } } }
/// <summary> /// Depending on the filterCategory string value, provides the implementation for IFlightFilter interfce /// </summary> /// <param name="filterCategoty">FilterCategory string </param> /// <returns>object implementing the IFlightFilter interface</returns> public IFlightFilter GetFlightFilterImplementation(string filterCategoty, IFlightBuilder flightBuilder) { IFlightFilter flightFilter = null; switch (filterCategoty) { case "0": flightFilter = (IFlightFilter)Activator.CreateInstance(typeof(FlightFilter), flightBuilder); break; case "1": flightFilter = (IFlightFilter)Activator.CreateInstance(typeof(FlightFilter1), flightBuilder); break; case "2": flightFilter = (IFlightFilter)Activator.CreateInstance(typeof(FlightFilter2), flightBuilder); break; case "3": flightFilter = (IFlightFilter)Activator.CreateInstance(typeof(FlightFilter3), flightBuilder); break; } return(flightFilter); }
public void ArrivalBeforeDepartureFilterTest() { var filter = new IFlightFilter[] { new ArrivalBeforeDepartureFilter() }; #region TestVariables var flights = new List <Flight> { new() { Segments = new Collection <Segment> { new() { DepartureDate = DateTime.Today + TimeSpan.FromDays(3), ArrivalDate = DateTime.Today + TimeSpan.FromDays(4) }, new() { DepartureDate = DateTime.Today + TimeSpan.FromDays(4), ArrivalDate = DateTime.Today + TimeSpan.FromDays(5) } } }, new() { Segments = new Collection <Segment> { new() { DepartureDate = DateTime.Today + TimeSpan.FromDays(10), ArrivalDate = DateTime.Today + TimeSpan.FromDays(11) }, new() { DepartureDate = DateTime.Today + TimeSpan.FromDays(12), ArrivalDate = DateTime.Today + TimeSpan.FromDays(13) } } } }; var flightToBeFiltered = new Flight { Segments = new Collection <Segment> { new() { DepartureDate = DateTime.Today - TimeSpan.FromDays(2), ArrivalDate = DateTime.Today + TimeSpan.FromDays(1) }, new() { DepartureDate = DateTime.Today, ArrivalDate = DateTime.Today - TimeSpan.FromDays(3) } } }; #endregion flights.Add(flightToBeFiltered); var filterResult = flights.Filter(filter); Assert.DoesNotContain(flightToBeFiltered, filterResult); }
public void Setup() { this._currentDate = DateTime.Now; this._flightFilter = new SpendMoreThan2HoursOnTheGroundFlightFilter(); }
public void Setup() { this._currentDate = DateTime.Now; this._flightFilter = new ArrivalDateBeforeDepartureDateFlightFilter(); }