/// <summary>
        /// Copies the aircraft information from FSX into the flight simulator aircraft list.
        /// </summary>
        /// <param name="fsxAircraft"></param>
        private void UpdateFlightSimulatorAircraftList(ReadAircraftInformation fsxAircraft)
        {
            lock(FlightSimulatorAircraftList.ListSyncLock) {
                IAircraft aircraft;
                if(FlightSimulatorAircraftList.Aircraft.Count != 0) aircraft = FlightSimulatorAircraftList.Aircraft[0];
                else {
                    aircraft = Factory.Singleton.Resolve<IAircraft>();
                    aircraft.Icao24 = "000000";
                    aircraft.UniqueId = 1;
                    FlightSimulatorAircraftList.Aircraft.Add(aircraft);
                }

                _MaximumAirspeed = fsxAircraft.MaxAirspeedIndicated;

                lock(aircraft) {
                    var now = Provider.UtcNow;
                    aircraft.DataVersion = now.Ticks;
                    aircraft.Latitude = (float)fsxAircraft.Latitude;
                    aircraft.Longitude = (float)fsxAircraft.Longitude;
                    aircraft.GroundSpeed = (int)fsxAircraft.AirspeedIndicated;
                    aircraft.Track = (float)fsxAircraft.TrueHeading;
                    aircraft.Type = fsxAircraft.Type;
                    aircraft.Model = fsxAircraft.Model;
                    aircraft.Operator = fsxAircraft.Operator;
                    aircraft.Registration = fsxAircraft.Registration;
                    aircraft.Squawk = fsxAircraft.Squawk;
                    if(fsxAircraft.OnGround) {
                        aircraft.Altitude = 0;
                        aircraft.VerticalRate = 0;
                    } else {
                        aircraft.Altitude = (int)fsxAircraft.Altitude;
                        aircraft.VerticalRate = (int)fsxAircraft.VerticalSpeed;
                    }

                    aircraft.UpdateCoordinates(now, _ShortTrailLengthSeconds);
                }
            }
        }
        public void TestInitialise()
        {
            _OriginalClassFactory = Factory.Singleton.CreateChildFactory();

            _SimConnect = TestUtilities.CreateMockImplementation<ISimConnectWrapper>();
            _SimConnect.Setup(m => m.IsInstalled).Returns(true);

            _Fsx = Factory.Singleton.Resolve<IFlightSimulatorX>();

            _ClientEventIdMap = new Dictionary<string,Enum>();
            _SimConnect.Setup(m => m.MapClientEventToSimEvent(It.IsAny<Enum>(), It.IsAny<string>())).Callback((Enum id, string name) => { _ClientEventIdMap.Add(name, id); });

            _SystemEventIdMap = new Dictionary<string,Enum>();
            _SimConnect.Setup(m => m.SubscribeToSystemEvent(It.IsAny<Enum>(), It.IsAny<string>())).Callback((Enum id, string name) => { _SystemEventIdMap.Add(name, id); });

            _NotificationGroupMap = new Dictionary<Enum,Enum>();
            _SimConnect.Setup(m => m.AddClientEventToNotificationGroup(It.IsAny<Enum>(), It.IsAny<Enum>(), false)).Callback((Enum groupId, Enum eventId, bool maskable) => { _NotificationGroupMap.Add(eventId, groupId); });

            _ReadAircraftInformationDefinitionId = default(Enum);
            _SimConnect.Setup(m => m.RegisterDataDefineStruct<ReadAircraftInformation>(It.IsAny<Enum>())).Callback((Enum definitionId) => { _ReadAircraftInformationDefinitionId = definitionId; });

            _AircraftInformationRequestId = default(Enum);
            _SimConnect.Setup(m => m.RequestDataOnSimObjectType(It.IsAny<Enum>(), It.IsAny<Enum>(), It.IsAny<uint>(), It.IsAny<int>())).Callback((Enum requestId, Enum definitionId, uint radius, int objectType) => {
                if(definitionId == _ReadAircraftInformationDefinitionId) _AircraftInformationRequestId = requestId;
            });

            _WriteAircraftInformationDefinitionId = default(Enum);
            _SimConnect.Setup(m => m.RegisterDataDefineStruct<WriteAircraftInformation>(It.IsAny<Enum>())).Callback((Enum definitionId) => { _WriteAircraftInformationDefinitionId = definitionId; });

            _ConnectionStatusChangedEvent = new EventRecorder<EventArgs>();
            _FreezeStatusChangedEvent = new EventRecorder<EventArgs>();
            _SlewStatusChangedEvent = new EventRecorder<EventArgs>();
            _FlightSimulatorXExceptionRaisedEvent = new EventRecorder<EventArgs<FlightSimulatorXException>>();
            _AircraftInformationReceivedEvent = new EventRecorder<EventArgs<ReadAircraftInformation>>();
            _SlewToggledEvent = new EventRecorder<EventArgs>();

            _ReadAircraftInformation = new ReadAircraftInformation();
            _WriteAircraftInformation = new WriteAircraftInformation();
            _Message = new Message();
        }
        public void FlightSimulatorXPresenter_Requested_Aircraft_Information_Is_Copied_Into_FlightSimulatorAircraftList()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            _Presenter.Initialise(_View.Object);

            var utcNow = worksheet.DateTime("UtcNow");
            _Provider.Setup(p => p.UtcNow).Returns(utcNow);

            var aircraftInformation = new ReadAircraftInformation() {
                AirspeedIndicated = worksheet.Double("FSXAirspeedIndicated"),
                Altitude = worksheet.Double("FSXAltitude"),
                Latitude = worksheet.Double("FSXLatitude"),
                Longitude = worksheet.Double("FSXLongitude"),
                MaxAirspeedIndicated = worksheet.Double("FSXMaxAirspeedIndicated"),
                Model = worksheet.String("FSXModel"),
                OnGround = worksheet.Bool("FSXOnGround"),
                Operator = worksheet.String("FSXOperator"),
                Registration = worksheet.String("FSXRegistration"),
                Squawk = worksheet.Int("FSXSquawk"),
                TrueHeading = worksheet.Double("FSXTrueHeading"),
                Type = worksheet.String("FSXType"),
                VerticalSpeed = worksheet.Double("FSXVerticalSpeed"),
            };
            _FlightSimulatorX.Raise(f => f.AircraftInformationReceived += null, new EventArgs<ReadAircraftInformation>(aircraftInformation));

            Assert.AreEqual(1, _FSXAircraftList.Count);
            var aircraft = _FSXAircraftList[0];
            Assert.AreEqual(worksheet.String("Icao24"), aircraft.Icao24);
            Assert.AreEqual(worksheet.Int("UniqueId"), aircraft.UniqueId);
            Assert.AreEqual(worksheet.NFloat("Latitude"), aircraft.Latitude);
            Assert.AreEqual(worksheet.NFloat("Longitude"), aircraft.Longitude);
            Assert.AreEqual(utcNow.Ticks, aircraft.DataVersion);
            Assert.AreEqual(worksheet.NFloat("GroundSpeed"), aircraft.GroundSpeed);
            Assert.AreEqual(worksheet.NFloat("Track"), aircraft.Track);
            Assert.AreEqual(worksheet.String("Type"), aircraft.Type);
            Assert.AreEqual(worksheet.String("Model"), aircraft.Model);
            Assert.AreEqual(worksheet.String("Operator"), aircraft.Operator);
            Assert.AreEqual(worksheet.String("Registration"), aircraft.Registration);
            Assert.AreEqual(worksheet.NInt("Squawk"), aircraft.Squawk);
            Assert.AreEqual(worksheet.NInt("Altitude"), aircraft.Altitude);
            Assert.AreEqual(worksheet.NInt("VerticalRate"), aircraft.VerticalRate);
        }
 /// <summary>
 /// Raises the event on the SimConnect wrapper that causes the <see cref="ReadAircraftInformation"/> object passed across
 /// to be picked up by the FSX object.
 /// </summary>
 /// <param name="readAircraft"></param>
 private void SendAircraftInformation(ReadAircraftInformation readAircraft)
 {
     _SimConnect.Raise(m => m.ObjectReceived += null, new SimConnectObjectReceivedEventArgs() {
         DefineId = Convert.ToUInt32(_ReadAircraftInformationDefinitionId),
         Data = new object[] { readAircraft } });
 }