public void AircraftType_ToString_Returns_Standardised_Text()
        {
            var aircraftType = new AircraftType();

            Assert.AreEqual("", aircraftType.ToString());

            aircraftType.Type = "B";
            Assert.AreEqual("B", aircraftType.ToString());
        }
 public void AircraftType_Constructor_Initialises_To_Known_State_And_Properties_Work()
 {
     var aircraftType = new AircraftType();
     TestUtilities.TestProperty(aircraftType, r => r.Engines, null, "Bb");
     TestUtilities.TestProperty(aircraftType, r => r.EngineType, EngineType.None, EngineType.Jet);
     TestUtilities.TestProperty(aircraftType, r => r.Species, Species.None, Species.Landplane);
     TestUtilities.TestProperty(aircraftType, r => r.Type, null, "Uu");
     TestUtilities.TestProperty(aircraftType, r => r.WakeTurbulenceCategory, WakeTurbulenceCategory.None, WakeTurbulenceCategory.Medium);
     Assert.AreEqual(0, aircraftType.Manufacturers.Count);
     Assert.AreEqual(0, aircraftType.Models.Count);
 }
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public AircraftType FindAircraftType(string type)
        {
            AircraftType result = null;

            lock(Lock) {
                if(_FilesValid) {
                    using(var connection = CreateOpenConnection()) {
                        Sql.RunSql(connection, null,
                            "SELECT [Icao]" +
                            "      ,[WakeTurbulenceId]" +
                            "      ,[SpeciesId]" +
                            "      ,[EngineTypeId]" +
                            "      ,[Engines]" +
                            "      ,[Model]" +
                            "      ,[Manufacturer]" +
                            "  FROM [AircraftTypeNoEnumsView]" +
                            " WHERE [Icao] = @icao",
                        new Dictionary<string,object>() {
                            { "@icao", type },
                        }, (reader) => {
                            if(result == null) {
                                result = new AircraftType() {
                                    Type =  Sql.GetString(reader, 0),
                                    WakeTurbulenceCategory = (WakeTurbulenceCategory)Sql.GetInt32(reader, 1),
                                    Species = (Species)Sql.GetInt32(reader, 2),
                                    EngineType = (EngineType)Sql.GetInt32(reader, 3),
                                    Engines = Sql.GetString(reader, 4),
                                };
                            }
                            result.Models.Add(Sql.GetString(reader, 5));
                            var manufacturer = Sql.GetString(reader, 6);
                            if(!String.IsNullOrEmpty(manufacturer)) result.Manufacturers.Add(manufacturer);
                            return true;
                        }, false, null);
                    }
                }
            }

            return result;
        }
        public void BaseStationAircraftList_Heartbeat_Periodically_Refreshes_Icao8643_Details()
        {
            _Configuration.BaseStationSettings.DisplayTimeoutSeconds = (MinutesBetweenDetailRefresh * 60) + 1;
            _ConfigurationStorage.Raise(c => c.ConfigurationChanged += null, EventArgs.Empty);
            _BaseStationAircraft.ICAOTypeCode = "747";

            _AircraftList.Start();

            // Initialise timer
            var time = DateTime.UtcNow;
            _Provider.Setup(p => p.UtcNow).Returns(time);
            _HeartbeatService.Raise(h => h.FastTick += null, EventArgs.Empty);

            // Message received when no information exists in lookup service
            _Port30003Listener.Raise(m => m.Port30003MessageReceived += null, _BaseStationMessageEventArgs);

            // Add entry to lookup service
            var aircraftType = new AircraftType() {
                Engines = "C",
                EngineType = EngineType.Piston,
                Species = Species.Landplane,
                WakeTurbulenceCategory = WakeTurbulenceCategory.Medium,
            };
            _StandingDataManager.Setup(m => m.FindAircraftType("747")).Returns(aircraftType);

            // Heartbeat 1 millisecond before refresh is allowed
            _Provider.Setup(p => p.UtcNow).Returns(time.AddMinutes(MinutesBetweenDetailRefresh).AddMilliseconds(-1));
            _HeartbeatService.Raise(h => h.FastTick += null, EventArgs.Empty);
            Assert.AreEqual(null, _AircraftList.FindAircraft(0x4008F6).NumberOfEngines);

            // Heartbeat on the refresh interval
            _Provider.Setup(p => p.UtcNow).Returns(time.AddMinutes(MinutesBetweenDetailRefresh));
            _HeartbeatService.Raise(h => h.FastTick += null, EventArgs.Empty);

            var aircraft = _AircraftList.FindAircraft(0x4008F6);
            Assert.AreEqual("C", aircraft.NumberOfEngines);
            Assert.AreEqual(EngineType.Piston, aircraft.EngineType);
            Assert.AreEqual(Species.Landplane, aircraft.Species);
            Assert.AreEqual(WakeTurbulenceCategory.Medium, aircraft.WakeTurbulenceCategory);
            Assert.AreEqual("747", aircraft.Type);
        }
        public void BaseStationAircraftList_MessageReceived_Looks_Up_Icao8643_Details()
        {
            var aircraftType = new AircraftType() {
                Engines = "C",
                EngineType = EngineType.Piston,
                Manufacturers = { "UNUSED 1" },
                Models = { "UNUSED 2" },
                Species = Species.Landplane,
                Type = "UNUSED",
                WakeTurbulenceCategory = WakeTurbulenceCategory.Medium,
            };
            _StandingDataManager.Setup(m => m.FindAircraftType("747")).Returns(aircraftType);

            _BaseStationAircraft.ICAOTypeCode = "747";
            _BaseStationAircraft.Manufacturer = "USED MAN";
            _BaseStationAircraft.Type = "USED MOD";

            _AircraftList.Start();
            _Port30003Listener.Raise(m => m.Port30003MessageReceived += null, _BaseStationMessageEventArgs);

            var aircraft = _AircraftList.FindAircraft(0x4008F6);
            Assert.AreEqual("C", aircraft.NumberOfEngines);
            Assert.AreEqual(EngineType.Piston, aircraft.EngineType);
            Assert.AreEqual(Species.Landplane, aircraft.Species);
            Assert.AreEqual(WakeTurbulenceCategory.Medium, aircraft.WakeTurbulenceCategory);
            Assert.AreEqual("747", aircraft.Type);
            Assert.AreEqual("USED MAN", aircraft.Manufacturer);
            Assert.AreEqual("USED MOD", aircraft.Model);
        }
 private static void ApplyAircraftType(IAircraft aircraft, AircraftType typeDetails)
 {
     if(typeDetails != null) {
         aircraft.NumberOfEngines = typeDetails.Engines;
         aircraft.EngineType = typeDetails.EngineType;
         aircraft.Species = typeDetails.Species;
         aircraft.WakeTurbulenceCategory = typeDetails.WakeTurbulenceCategory;
     }
 }