public void Airport_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var airport = new Airport();

            TestUtilities.TestProperty(airport, r => r.AltitudeFeet, null, 1);
            TestUtilities.TestProperty(airport, r => r.Country, null, "xX");
            TestUtilities.TestProperty(airport, r => r.IataCode, null, "Aa");
            TestUtilities.TestProperty(airport, r => r.IcaoCode, null, "An");
            TestUtilities.TestProperty(airport, r => r.Latitude, null, -12.345);
            TestUtilities.TestProperty(airport, r => r.Longitude, null, 34.123);
            TestUtilities.TestProperty(airport, r => r.Name, null, "Bb");
        }
        public void Describe_Airport_Formats_Airport_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var airport = new Airport();
            airport.IcaoCode = worksheet.EString("Icao");
            airport.IataCode = worksheet.EString("Iata");
            airport.Name = worksheet.EString("Name");
            airport.Country = worksheet.EString("Country");

            var result = Describe.Airport(airport, worksheet.Bool("PreferIata"), worksheet.Bool("ShowCode"), worksheet.Bool("ShowName"), worksheet.Bool("ShowCountry"));

            Assert.AreEqual(worksheet.EString("Result"), result);
        }
        /// <summary>
        /// Returns a standard description of an airport.
        /// </summary>
        /// <param name="airport"></param>
        /// <param name="preferIataAirportCode"></param>
        /// <param name="showCode"></param>
        /// <param name="showName"></param>
        /// <param name="showCountry"></param>
        /// <returns></returns>
        public static string Airport(Airport airport, bool preferIataAirportCode, bool showCode = true, bool showName = true, bool showCountry = true)
        {
            StringBuilder result = new StringBuilder();

            if(airport != null) {
                if(showCode) {
                    var firstChoice = preferIataAirportCode ? airport.IataCode : airport.IcaoCode;
                    var secondChoice = preferIataAirportCode ? airport.IcaoCode : airport.IataCode;
                    if(!String.IsNullOrEmpty(firstChoice))          result.Append(firstChoice);
                    else if(!String.IsNullOrEmpty(secondChoice))    result.Append(secondChoice);
                }
                if(showName && !String.IsNullOrEmpty(airport.Name))         AddSeparator(result, " ").Append(airport.Name);
                if(showCountry && !String.IsNullOrEmpty(airport.Country))   AddSeparator(result, ", ").Append(airport.Country);
            }

            return result.ToString();
        }
        public void Airport_ToString_Returns_Standardised_Text()
        {
            var airport = new Airport();

            airport.IataCode = "IATA";
            airport.IcaoCode = "ICAO";
            airport.Name = "NAME";
            airport.Country = "COUNTRY";

            Assert.AreEqual("ICAO NAME, COUNTRY", airport.ToString());

            airport.IcaoCode = null;
            Assert.AreEqual("IATA NAME, COUNTRY", airport.ToString());

            airport.IcaoCode = "";
            Assert.AreEqual("IATA NAME, COUNTRY", airport.ToString());

            airport.IcaoCode = "ICAO";
            airport.Country = null;
            Assert.AreEqual("ICAO NAME", airport.ToString());
        }
        /// <summary>
        /// Creates an airport object from the constituent parts passed across.
        /// </summary>
        /// <param name="icao"></param>
        /// <param name="iata"></param>
        /// <param name="name"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="altitude"></param>
        /// <param name="location"></param>
        /// <param name="country"></param>
        /// <returns></returns>
        private Airport CreateAirport(string icao, string iata, string name, double? latitude, double? longitude, int? altitude, string location, string country)
        {
            var result = new Airport() {
                IcaoCode = icao,
                IataCode = iata,
                Latitude = latitude,
                Longitude = longitude,
                AltitudeFeet = altitude,
                Country = country,
            };
            result.Name = Describe.AirportName(name, location);

            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>();
        }
        private int BuildAirportJson(Airport sdmAirport, Dictionary<string, int> airportMap, List<ReportAirportJson> jsonList)
        {
            int result = -1;

            if(sdmAirport != null) {
                var code = String.IsNullOrEmpty(sdmAirport.IcaoCode) ? sdmAirport.IataCode : sdmAirport.IcaoCode;
                if(!String.IsNullOrEmpty(code)) {
                    if(!airportMap.TryGetValue(code, out result)) {
                        result = jsonList.Count;
                        jsonList.Add(new ReportAirportJson() { Code = code, Name = Describe.Airport(sdmAirport, false, false, true, true) });
                        airportMap.Add(code, result);
                    }
                }
            }

            return result;
        }