public void FlightReportJson_Constructor_Initialises_To_Known_State_And_Properties_Work() { var json = new FlightReportJson(); TestUtilities.TestProperty(json, "CountRows", null, 1); TestUtilities.TestProperty(json, "ErrorText", null, "Ab"); TestUtilities.TestProperty(json, "FromDate", null, "Ab"); TestUtilities.TestProperty(json, "GroupBy", null, "Ab"); TestUtilities.TestProperty(json, "ProcessingTime", null, "Ab"); TestUtilities.TestProperty(json, "ToDate", null, "Ab"); Assert.AreEqual(0, json.Aircraft.Count); Assert.AreEqual(0, json.Airports.Count); Assert.AreEqual(0, json.Flights.Count); Assert.AreEqual(0, json.Routes.Count); }
/// <summary> /// Builds up rows for a report that wants information on flights for many aircraft simultaneously. /// </summary> /// <param name="args"></param> /// <param name="parameters"></param> /// <returns></returns> private FlightReportJson CreateManyAircraftReport(RequestReceivedEventArgs args, Parameters parameters) { FlightReportJson json = new FlightReportJson(); json.FromDate = FormatReportDate(parameters.FromDate); json.ToDate = FormatReportDate(parameters.ToDate); bool hasNonDatabaseCriteria = parameters.IsMilitary || parameters.WakeTurbulenceCategory != null || parameters.Species != null; if(!hasNonDatabaseCriteria) json.CountRows = BaseStationDatabase.GetCountOfFlights(parameters); var dbFlights = BaseStationDatabase.GetFlights( parameters, hasNonDatabaseCriteria ? -1 : parameters.FromRow, hasNonDatabaseCriteria ? -1 : parameters.ToRow, parameters.SortField1, parameters.SortAscending1, parameters.SortField2, parameters.SortAscending2); if(hasNonDatabaseCriteria) { dbFlights = dbFlights.Where(f => { bool matches = f.Aircraft != null; if(matches) { if(parameters.IsMilitary) { var codeBlock = StandingDataManager.FindCodeBlock(f.Aircraft.ModeS); matches = matches && codeBlock != null && codeBlock.IsMilitary; } if(parameters.Species != null || parameters.WakeTurbulenceCategory != null) { var aircraftType = StandingDataManager.FindAircraftType(f.Aircraft.ICAOTypeCode); if(parameters.Species != null) matches = matches && aircraftType != null && aircraftType.Species == parameters.Species; if(parameters.WakeTurbulenceCategory != null) matches = matches && aircraftType != null && aircraftType.WakeTurbulenceCategory == parameters.WakeTurbulenceCategory; } } return matches; }).ToList(); json.CountRows = dbFlights.Count; int limit = parameters.ToRow == -1 || parameters.ToRow < parameters.FromRow ? int.MaxValue : (parameters.ToRow - Math.Max(0, parameters.FromRow)) + 1; int offset = parameters.FromRow < 0 ? 0 : parameters.FromRow; dbFlights = dbFlights.Skip(offset).Take(limit).ToList(); } TranscribeDatabaseRecordsToJson(dbFlights, json.Flights, json.Aircraft, json.Airports, json.Routes, args, parameters); return json; }