public void Plugin_Aircraft_Record_Written_When_First_Message_From_Aircraft_Received()
        {
            SetEnabledOption(true);

            BaseStationAircraft aircraft = null;
            _BaseStationDatabase.Setup(d => d.GetAircraftByCode("X")).Returns((BaseStationAircraft)null);
            _BaseStationDatabase.Setup(d => d.InsertAircraft(It.IsAny<BaseStationAircraft>())).Callback((BaseStationAircraft a) => { aircraft = a; });

            var codeBlock = new CodeBlock() { Country = "Elbonia" };
            _StandingDataManager.Setup(m => m.FindCodeBlock("X")).Returns(codeBlock);

            _Plugin.Startup(_StartupParameters);

            var message = new BaseStationMessage() { AircraftId = 99, Icao24 = "X", MessageType = BaseStationMessageType.Transmission, TransmissionType = BaseStationTransmissionType.AirToAir };
            _Listener.Raise(r => r.Port30003MessageReceived += null, new BaseStationMessageEventArgs(message));

            _BaseStationDatabase.Verify(d => d.InsertAircraft(It.IsAny<BaseStationAircraft>()), Times.Once());
            Assert.AreEqual(0, aircraft.AircraftID);
            Assert.AreEqual("X", aircraft.ModeS);
            Assert.AreEqual("Elbonia", aircraft.ModeSCountry);
            Assert.AreEqual(_Provider.Object.LocalNow, aircraft.FirstCreated);
            Assert.AreEqual(_Provider.Object.LocalNow, aircraft.LastModified);
            Assert.AreEqual(null, aircraft.AircraftClass);
            Assert.AreEqual(null, aircraft.CofACategory);
            Assert.AreEqual(null, aircraft.CofAExpiry);
            Assert.AreEqual(null, aircraft.Country);
            Assert.AreEqual(null, aircraft.CurrentRegDate);
            Assert.AreEqual(null, aircraft.DeRegDate);
            Assert.AreEqual(null, aircraft.Engines);
            Assert.AreEqual(null, aircraft.FirstRegDate);
            Assert.AreEqual(null, aircraft.GenericName);
            Assert.AreEqual(null, aircraft.ICAOTypeCode);
            Assert.AreEqual(null, aircraft.InfoUrl);
            Assert.AreEqual(false, aircraft.Interested);
            Assert.AreEqual(null, aircraft.Manufacturer);
            Assert.AreEqual(null, aircraft.MTOW);
            Assert.AreEqual(null, aircraft.OperatorFlagCode);
            Assert.AreEqual(null, aircraft.OwnershipStatus);
            Assert.AreEqual(null, aircraft.PictureUrl1);
            Assert.AreEqual(null, aircraft.PictureUrl2);
            Assert.AreEqual(null, aircraft.PictureUrl3);
            Assert.AreEqual(null, aircraft.PopularName);
            Assert.AreEqual(null, aircraft.PreviousID);
            Assert.AreEqual(null, aircraft.RegisteredOwners);
            Assert.AreEqual(null, aircraft.Registration);
            Assert.AreEqual(null, aircraft.SerialNo);
            Assert.AreEqual(null, aircraft.Status);
            Assert.AreEqual(null, aircraft.TotalHours);
            Assert.AreEqual(null, aircraft.Type);
            Assert.AreEqual(null, aircraft.UserNotes);
            Assert.AreEqual(null, aircraft.YearBuilt);
        }
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="icao24"></param>
        /// <returns></returns>
        public CodeBlock FindCodeBlock(string icao24)
        {
            CodeBlock result = null;

            if(!String.IsNullOrEmpty(icao24)) {
                int icaoValue;
                try {
                    icaoValue = Convert.ToInt32(icao24, 16);
                } catch {
                    icaoValue = -1;
                }

                if(icaoValue != -1) {
                    lock(Lock) {
                        foreach(var entry in _CodeBlockCache) {
                            if(entry.CodeMatches(icaoValue)) {
                                result = entry.CodeBlock;
                                break;
                            }
                        }
                        if(result == null && _FilesValid) result = new CodeBlock();
                    }
                }
            }

            return result;
        }
 /// <summary>
 /// Applies the code block to the aircraft.
 /// </summary>
 /// <param name="aircraft"></param>
 /// <param name="codeBlock"></param>
 private static void ApplyCodeBlock(IAircraft aircraft, CodeBlock codeBlock)
 {
     if(codeBlock != null) {
         aircraft.Icao24Country = codeBlock.Country;
         aircraft.IsMilitary = codeBlock.IsMilitary;
     }
 }
        public void BaseStationAircraftList_MessageReceived_Looks_Up_Codeblock_Details()
        {
            var codeblock1 = new CodeBlock() { Country = "UK", IsMilitary = false, };
            _StandingDataManager.Setup(m => m.FindCodeBlock("1")).Returns(codeblock1);

            var dbRecord1 = new BaseStationAircraft();
            _BaseStationDatabase.Setup(m => m.GetAircraftByCode("1")).Returns(dbRecord1);
            dbRecord1.Country = "UNUSED";
            dbRecord1.ModeSCountry = "UNUSED";

            var codeBlock2 = new CodeBlock() { IsMilitary = true, };
            _StandingDataManager.Setup(m => m.FindCodeBlock("2")).Returns(codeBlock2);

            _AircraftList.Start();

            _BaseStationMessage.Icao24 = "1";
            _Port30003Listener.Raise(m => m.Port30003MessageReceived += null, _BaseStationMessageEventArgs);

            _BaseStationMessage.Icao24 = "2";
            _Port30003Listener.Raise(m => m.Port30003MessageReceived += null, _BaseStationMessageEventArgs);

            var aircraft1 = _AircraftList.FindAircraft(1);
            Assert.AreEqual("UK", aircraft1.Icao24Country);
            Assert.AreEqual(false, aircraft1.IsMilitary);

            var aircraft2 = _AircraftList.FindAircraft(2);
            Assert.AreEqual(true, aircraft2.IsMilitary);
        }
 public void CodeBlock_Constructor_Initialises_To_Known_State_And_Properties_Work()
 {
     var codeBlock = new CodeBlock();
     TestUtilities.TestProperty(codeBlock, r => r.Country, null, "Ab");
     TestUtilities.TestProperty(codeBlock, r => r.IsMilitary, false);
 }