public void Route_Constructor_Initialises_To_Known_State_And_Properties_Work() { var route = new Route(); TestUtilities.TestProperty(route, r => r.From, null, new Airport()); TestUtilities.TestProperty(route, r => r.To, null, new Airport()); Assert.AreEqual(0, route.Stopovers.Count); }
/// <summary> /// See interface docs. /// </summary> /// <param name="callSign"></param> /// <returns></returns> public Route FindRoute(string callSign) { Route result = null; const string selectFields = "SELECT [RouteId]" + " ,[FromAirportIcao]" + " ,[FromAirportIata]" + " ,[FromAirportName]" + " ,[FromAirportLatitude]" + " ,[FromAirportLongitude]" + " ,[FromAirportAltitude]" + " ,[FromAirportLocation]" + " ,[FromAirportCountry]" + " ,[ToAirportIcao]" + " ,[ToAirportIata]" + " ,[ToAirportName]" + " ,[ToAirportLatitude]" + " ,[ToAirportLongitude]" + " ,[ToAirportAltitude]" + " ,[ToAirportLocation]" + " ,[ToAirportCountry]" + " FROM [RouteView]"; if(!String.IsNullOrEmpty(callSign)) { string airlineCode = null, flightCode = null; if(_DatabaseVersion < 3) SplitCallsign(callSign, out airlineCode, out flightCode); if(_DatabaseVersion >= 3 || (!String.IsNullOrEmpty(airlineCode) && !String.IsNullOrEmpty(flightCode) && (airlineCode.Length == 2 || airlineCode.Length == 3))) { lock(Lock) { if(_FilesValid) { using(var connection = CreateOpenConnection()) { var selectCommand = selectFields; var parameters = new Dictionary<string, object>(); if(_DatabaseVersion >= 3) { selectCommand = String.Format("{0} WHERE [Callsign] = @callsign", selectCommand); parameters.Add("@callsign", callSign); } else { var airlineField = airlineCode.Length == 2 ? "Iata" : "Icao"; selectCommand = String.Format("{0} WHERE [Operator{1}] = @airlineCode AND [FlightNumber] = @flightCode", selectCommand, airlineField); parameters.Add("@airlineCode", airlineCode); parameters.Add("@flightCode", flightCode); } Sql.RunSql(connection, null, selectCommand, parameters, (reader) => { var routeId = Sql.GetInt64(reader, 0); result = new Route() { From = CreateAirport( icao: Sql.GetString(reader, 1), iata: Sql.GetString(reader, 2), name: Sql.GetString(reader, 3), latitude: Sql.GetNDouble(reader, 4), longitude: Sql.GetNDouble(reader, 5), altitude: Sql.GetNInt32(reader, 6), location: Sql.GetString(reader, 7), country: Sql.GetString(reader, 8) ), To = CreateAirport( icao: Sql.GetString(reader, 9), iata: Sql.GetString(reader, 10), name: Sql.GetString(reader, 11), latitude: Sql.GetNDouble(reader, 12), longitude: Sql.GetNDouble(reader, 13), altitude: Sql.GetNInt32(reader, 14), location: Sql.GetString(reader, 15), country: Sql.GetString(reader, 16) ), }; LoadStopovers(connection, null, null, routeId, result.Stopovers); return false; }, false, null); } } } } } return result; }
public void TestInitialise() { _BackgroundException = null; _ClassFactorySnapshot = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton<IRuntimeEnvironment>(); _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(m => m.Load()).Returns(_Configuration); _AircraftPictureManager = TestUtilities.CreateMockSingleton<IAircraftPictureManager>(); _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>(); _AutoConfigPictureFolderCache = TestUtilities.CreateMockSingleton<IAutoConfigPictureFolderCache>(); _PictureDirectoryCache = new Mock<IDirectoryCache>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _AutoConfigPictureFolderCache.Setup(a => a.DirectoryCache).Returns(_PictureDirectoryCache.Object); _AircraftList = Factory.Singleton.Resolve<IBaseStationAircraftList>(); _AircraftList.ExceptionCaught += AircraftListExceptionCaughtHandler; _Provider = new Mock<IBaseStationAircraftListProvider>().SetupAllProperties(); _Provider.Setup(m => m.UtcNow).Returns(DateTime.UtcNow); _Port30003Listener = new Mock<IListener>().SetupAllProperties(); _BaseStationDatabase = new Mock<IBaseStationDatabase>().SetupAllProperties(); _StandingDataManager = TestUtilities.CreateMockSingleton<IStandingDataManager>(); _AircraftList.Provider = _Provider.Object; _AircraftList.Listener = _Port30003Listener.Object; _AircraftList.BaseStationDatabase = _BaseStationDatabase.Object; _AircraftList.StandingDataManager = _StandingDataManager.Object; _BaseStationMessage = new BaseStationMessage(); _BaseStationMessage.MessageType = BaseStationMessageType.Transmission; _BaseStationMessage.Icao24 = "4008F6"; _BaseStationMessageEventArgs = new BaseStationMessageEventArgs(_BaseStationMessage); _BaseStationAircraft = new BaseStationAircraft(); _BaseStationDatabase.Setup(m => m.GetAircraftByCode("4008F6")).Returns(_BaseStationAircraft); _Heathrow = new Airport() { IcaoCode = "EGLL", IataCode = "LHR", Name = "Heathrow", Country = "UK", }; _JohnFKennedy = new Airport() { IcaoCode = "KJFK", IataCode = "JFK", Country = "USA", }; _Helsinki = new Airport() { IataCode = "HEL", }; _Boston = new Airport() { IcaoCode = "KBOS", }; _Route = new Route() { From = _Heathrow, To = _JohnFKennedy, Stopovers = { _Helsinki }, }; _ExceptionCaughtEvent = new EventRecorder<EventArgs<Exception>>(); _CountChangedEvent = new EventRecorder<EventArgs>(); }
public void BaseStationAircraftList_MessageReceived_Updates_Route_When_Callsign_Changes() { _AircraftList.Start(); var routeOut = new Route() { From = _Heathrow, To = _JohnFKennedy }; var routeIn = new Route() { From = _JohnFKennedy, To = _Heathrow }; _StandingDataManager.Setup(m => m.FindRoute("VRS1")).Returns(routeOut); _StandingDataManager.Setup(m => m.FindRoute("VRS2")).Returns(routeIn); _BaseStationMessage.Callsign = "VRS1"; _Port30003Listener.Raise(m => m.Port30003MessageReceived += null, _BaseStationMessageEventArgs); _BaseStationMessage.Callsign = "VRS2"; _Port30003Listener.Raise(m => m.Port30003MessageReceived += null, _BaseStationMessageEventArgs); var aircraft = _AircraftList.FindAircraft(0x4008F6); Assert.AreEqual("EGLL Heathrow, UK", aircraft.Destination); }
/// <summary> /// Applies route data to the aircraft. /// </summary> /// <param name="aircraft"></param> /// <param name="route"></param> private void ApplyRoute(IAircraft aircraft, Route route) { if(route != null) { aircraft.Origin = Describe.Airport(route.From, _PreferIataAirportCodes); aircraft.Destination = Describe.Airport(route.To, _PreferIataAirportCodes); foreach(var stopover in route.Stopovers) { aircraft.Stopovers.Add(Describe.Airport(stopover, _PreferIataAirportCodes)); } } }