private void Do_BaseStationMessage_ToBaseStationString_Builds_Valid_BaseStation_Messages_From_A_BaseStationMessage_Object() { var worksheet = new ExcelWorksheetData(TestContext); _Implementation.MessageType = worksheet.ParseEnum <BaseStationMessageType>("MessageType"); _Implementation.TransmissionType = worksheet.ParseEnum <BaseStationTransmissionType>("TransmissionType"); _Implementation.StatusCode = worksheet.ParseEnum <BaseStationStatusCode>("StatusCode"); _Implementation.SessionId = worksheet.Int("SessionId"); _Implementation.AircraftId = worksheet.Int("AircraftId"); _Implementation.Icao24 = worksheet.String("Icao24"); _Implementation.FlightId = worksheet.Int("FlightId"); _Implementation.MessageGenerated = worksheet.DateTime("MessageGenerated"); _Implementation.MessageLogged = worksheet.DateTime("MessageLogged"); _Implementation.Callsign = worksheet.String("Callsign"); _Implementation.Altitude = worksheet.NInt("Altitude"); _Implementation.GroundSpeed = worksheet.NFloat("GroundSpeed"); _Implementation.Track = worksheet.NFloat("Track"); _Implementation.Latitude = worksheet.NDouble("Latitude"); _Implementation.Longitude = worksheet.NDouble("Longitude"); _Implementation.VerticalRate = worksheet.NInt("VerticalRate"); _Implementation.Squawk = worksheet.NInt("Squawk"); _Implementation.SquawkHasChanged = worksheet.NBool("SquawkHasChanged"); _Implementation.Emergency = worksheet.NBool("Emergency"); _Implementation.IdentActive = worksheet.NBool("IdentActive"); _Implementation.OnGround = worksheet.NBool("OnGround"); Assert.AreEqual(worksheet.String("Text"), _Implementation.ToBaseStationString()); }
public void BaseStationMessageTranslator_Translate_Translates_Messages_Correctly() { ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext); BaseStationMessage translated = _Implementation.Translate(worksheet.String("Text"), 123); Assert.AreEqual(Enum.Parse(typeof(BaseStationMessageType), worksheet.String("MessageType")), translated.MessageType); Assert.AreEqual(Enum.Parse(typeof(BaseStationTransmissionType), worksheet.String("TransmissionType")), translated.TransmissionType); Assert.AreEqual(Enum.Parse(typeof(BaseStationStatusCode), worksheet.String("StatusCode")), translated.StatusCode); Assert.AreEqual(worksheet.Int("SessionId"), translated.SessionId); Assert.AreEqual(worksheet.Int("AircraftId"), translated.AircraftId); Assert.AreEqual(worksheet.String("Icao24"), translated.Icao24); Assert.AreEqual(worksheet.Int("FlightId"), translated.FlightId); Assert.AreEqual(worksheet.DateTime("MessageGenerated"), translated.MessageGenerated); Assert.AreEqual(worksheet.DateTime("MessageLogged"), translated.MessageLogged); Assert.AreEqual(worksheet.String("Callsign"), translated.Callsign); Assert.AreEqual(worksheet.NFloat("Altitude"), translated.Altitude); Assert.AreEqual(worksheet.NFloat("GroundSpeed"), translated.GroundSpeed); Assert.AreEqual(worksheet.NFloat("Track"), translated.Track); Assert.AreEqual(worksheet.NDouble("Latitude"), translated.Latitude); Assert.AreEqual(worksheet.NDouble("Longitude"), translated.Longitude); Assert.AreEqual(worksheet.NFloat("VerticalRate"), translated.VerticalRate); Assert.AreEqual(worksheet.NInt("Squawk"), translated.Squawk); Assert.AreEqual(worksheet.NBool("SquawkHasChanged"), translated.SquawkHasChanged); Assert.AreEqual(worksheet.NBool("Emergency"), translated.Emergency); Assert.AreEqual(worksheet.NBool("IdentActive"), translated.IdentActive); Assert.AreEqual(worksheet.NBool("OnGround"), translated.OnGround); Assert.AreEqual(worksheet.Bool("IsMlat"), translated.IsMlat); }
public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly_For_Non_UK_Cultures() { var worksheet = new ExcelWorksheetData(TestContext); foreach (var culture in new string[] { "en-US", "de-DE", "fr-FR", "ru-RU" }) { using (var cultureSwitcher = new CultureSwitcher(culture)) { TestCleanup(); TestInitialise(); var obj = new ValueTypes() { BoolValue = worksheet.Bool("BoolValue"), UnusedBool = worksheet.Bool("UnusedBool"), NullableBool = worksheet.NBool("NullableBool"), Int = worksheet.Int("Int"), NullableInt = worksheet.NInt("NullableInt"), Long = worksheet.Long("Long"), NullableLong = worksheet.NLong("NullableLong"), Float = worksheet.Float("Float"), NullableFloat = worksheet.NFloat("NullableFloat"), Double = worksheet.Double("Double"), NullableDouble = worksheet.NDouble("NullableDouble"), DateTime = worksheet.DateTime("DateTime"), NullableDateTime = worksheet.NDateTime("NullableDateTime"), }; _JsonSerialiser.Initialise(typeof(ValueTypes)); _JsonSerialiser.WriteObject(_Stream, obj); var message = String.Format("when culture is {0}", culture); Assert.AreEqual(worksheet.EString("Json"), GetJson(), message); } } }
public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); var obj = new ValueTypes() { BoolValue = worksheet.Bool("BoolValue"), UnusedBool = worksheet.Bool("UnusedBool"), NullableBool = worksheet.NBool("NullableBool"), Int = worksheet.Int("Int"), NullableInt = worksheet.NInt("NullableInt"), Long = worksheet.Long("Long"), NullableLong = worksheet.NLong("NullableLong"), Float = worksheet.Float("Float"), NullableFloat = worksheet.NFloat("NullableFloat"), Double = worksheet.Double("Double"), NullableDouble = worksheet.NDouble("NullableDouble"), DateTime = worksheet.DateTime("DateTime"), NullableDateTime = worksheet.NDateTime("NullableDateTime"), }; _JsonSerialiser.Initialise(typeof(ValueTypes)); _JsonSerialiser.WriteObject(_Stream, obj); Assert.AreEqual(worksheet.EString("Json"), GetJson()); }
public void AircraftSanityChecker_FirstGoodAltitude_Returns_Correct_Values() { var worksheet = new ExcelWorksheetData(TestContext); //if(!worksheet.NBool("JustThis").GetValueOrDefault()) continue; var comments = worksheet.String("Comments"); for (var i = 1; i <= 5; ++i) { var altitude = worksheet.NInt(String.Format("Altitude{0}", i)); if (altitude != null) { var seconds = worksheet.Double(String.Format("Seconds{0}", i)); var time = new DateTime(2014, 8, 3).AddSeconds(seconds); var expectedResult = worksheet.NInt(String.Format("1stGood{0}", i)); _Checker.CheckAltitude(1, time, altitude.Value); var actualResult = _Checker.FirstGoodAltitude(1); Assert.AreEqual(expectedResult, actualResult, String.Format("Column {0} {1}", i, comments)); } } }
public void PolarPlotter_AddCoordinate_Adds_Plot_To_All_Applicable_Slices() { var worksheet = new ExcelWorksheetData(TestContext); var comment = worksheet.String("Comments"); //if(comment != "comment here") return; StandardInitialise(); for (var i = 1; i <= 2; ++i) { var altitude = worksheet.NInt(String.Format("Altitude{0}", i)); var latitude = worksheet.NDouble(String.Format("Latitude{0}", i)); var longitude = worksheet.NDouble(String.Format("Longitude{0}", i)); if (altitude != null && latitude != null && longitude != null) { _Plotter.AddCoordinate(1, altitude.Value, latitude.Value, longitude.Value); } } foreach (var slice in _Plotter.TakeSnapshot()) { string suffix; switch (slice.AltitudeHigher) { case 9: suffix = "-09"; break; case 19: suffix = slice.AltitudeLower == 10 ? "-19" : "-RG"; break; default: suffix = "-ALL"; break; } var nonZeroPolarPlots = slice.PolarPlots.Where(r => r.Value.Distance != 0).ToDictionary(r => r.Key, r => r.Value); Assert.AreEqual(worksheet.Int(String.Format("Count{0}", suffix)), nonZeroPolarPlots.Count, suffix); for (var i = 1; i <= nonZeroPolarPlots.Count; ++i) { var bearing = worksheet.Int(String.Format("Ang{0}{1}", i, suffix)); var plot = nonZeroPolarPlots[bearing]; Assert.AreEqual(worksheet.Int(String.Format("Alt{0}{1}", i, suffix)), plot.Altitude, suffix); Assert.AreEqual(worksheet.Double(String.Format("Dist{0}{1}", i, suffix)), plot.Distance, 0.0001, suffix); Assert.AreEqual(bearing, plot.Angle, suffix); } } }
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); }
public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly_For_Non_UK_Cultures() { var worksheet = new ExcelWorksheetData(TestContext); foreach(var culture in new string[] { "en-US", "de-DE", "fr-FR", "ru-RU" }) { using(var cultureSwitcher = new CultureSwitcher(culture)) { TestCleanup(); TestInitialise(); var obj = new ValueTypes() { BoolValue = worksheet.Bool("BoolValue"), UnusedBool = worksheet.Bool("UnusedBool"), NullableBool = worksheet.NBool("NullableBool"), Int = worksheet.Int("Int"), NullableInt = worksheet.NInt("NullableInt"), Long = worksheet.Long("Long"), NullableLong = worksheet.NLong("NullableLong"), Float = worksheet.Float("Float"), NullableFloat = worksheet.NFloat("NullableFloat"), Double = worksheet.Double("Double"), NullableDouble = worksheet.NDouble("NullableDouble"), DateTime = worksheet.DateTime("DateTime"), NullableDateTime = worksheet.NDateTime("NullableDateTime"), }; _JsonSerialiser.Initialise(typeof(ValueTypes)); _JsonSerialiser.WriteObject(_Stream, obj); var message = String.Format("when culture is {0}", culture); Assert.AreEqual(worksheet.EString("Json"), GetJson(), message); } } }
public void WebServer_Addresses_Are_Reported_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); _WebServer.Root = worksheet.String("Root"); _WebServer.Port = worksheet.NInt("Port") ?? 80; if(worksheet.String("IPAddresses") == null) _Provider.Setup(p => p.GetHostAddresses()).Returns((IPAddress[])null); else { var ipAddresses = new List<IPAddress>(); foreach(var chunk in worksheet.EString("IPAddresses").Split(',')) { if(chunk.Length > 0) ipAddresses.Add(IPAddress.Parse(chunk)); } _Provider.Setup(p => p.GetHostAddresses()).Returns(ipAddresses.ToArray()); } _WebServer.ExternalIPAddress = worksheet.EString("ExternalIPAddress"); _WebServer.ExternalPort = worksheet.NInt("UPnPExternalPort") ?? 80; Assert.AreEqual(worksheet.String("LocalAddress"), _WebServer.LocalAddress); Assert.AreEqual(worksheet.String("NetworkAddress"), _WebServer.NetworkAddress); Assert.AreEqual(worksheet.String("NetworkIPAddress"), _WebServer.NetworkIPAddress); Assert.AreEqual(worksheet.String("ExternalAddress"), _WebServer.ExternalAddress); }
public void RawMessageTranslator_Translate_Accepts_Icaos_As_Valid_Based_On_Number_Of_Times_Seen() { var worksheet = new ExcelWorksheetData(TestContext); _Translator.AcceptIcaoInPI0Count = worksheet.Int("PI0Count"); _Translator.AcceptIcaoInPI0Milliseconds = worksheet.Int("PI0Ms"); _Translator.AcceptIcaoInNonPICount = worksheet.Int("NonPICount"); _Translator.AcceptIcaoInNonPIMilliseconds = worksheet.Int("NonPIMs"); IEnumerable<ModeSMessage> messages; switch(worksheet.String("DownlinkFormat").ToUpper()) { case "HASPI": messages = CreateModeSMessagesWithPIField(); break; case "NOPI": messages = CreateModeSMessagesWithNoPIField(); break; default: throw new NotImplementedException(); } foreach(var message in messages) { message.Icao24 = CreateRandomIcao24(); var originalDF = message.DownlinkFormat; var originalParity = message.ParityInterrogatorIdentifier; for(var messageNumber = 1;messageNumber <= 3;++messageNumber) { var timeColumn = String.Format("Msg{0}Time", messageNumber); var acceptedColumn = String.Format("Accepted{0}", messageNumber); var piColumn = String.Format("Msg{0}PI", messageNumber); if(worksheet.String(acceptedColumn) != null) { message.DownlinkFormat = originalDF; message.ParityInterrogatorIdentifier = worksheet.NInt(piColumn); if(message.ParityInterrogatorIdentifier == null && originalParity != null) message.DownlinkFormat = DownlinkFormat.ShortAirToAirSurveillance; else if(message.ParityInterrogatorIdentifier != null && originalParity == null) message.DownlinkFormat = DownlinkFormat.ExtendedSquitter; var now = _NowUtc.AddMilliseconds(worksheet.Int(timeColumn)); _Provider.Setup(r => r.UtcNow).Returns(now); var accepted = _Translator.Translate(now, message, null) != null; var expected = worksheet.Bool(acceptedColumn); Assert.AreEqual(expected, accepted, "{0} message {1}: {2}", originalDF, messageNumber, worksheet.String("Comments")); } } } }
public void Plugin_Flight_Updates_Message_Counters_Correctly() { // These are the nullable integers which start with "Num" var worksheet = new ExcelWorksheetData(TestContext); SetEnabledOption(true); BaseStationFlight flight = null; _BaseStationDatabase.Setup(d => d.UpdateFlight(It.IsAny<BaseStationFlight>())).Callback((BaseStationFlight f) => { flight = f; }); _Plugin.Startup(_StartupParameters); var message = new BaseStationMessage() { Icao24 = "Z", MessageType = worksheet.ParseEnum<BaseStationMessageType>("MessageType"), TransmissionType = worksheet.ParseEnum<BaseStationTransmissionType>("TransmissionType"), StatusCode = worksheet.ParseEnum<BaseStationStatusCode>("StatusCode"), GroundSpeed = worksheet.NFloat("GroundSpeed"), Track = worksheet.NFloat("Track"), Latitude = worksheet.NFloat("Latitude"), Longitude = worksheet.NFloat("Longitude"), VerticalRate = worksheet.NInt("VerticalRate"), }; _Listener.Raise(r => r.Port30003MessageReceived += null, new BaseStationMessageEventArgs(message)); SetProviderTimes(_Provider.Object.LocalNow.AddMinutes(MinutesBeforeFlightClosed)); _HeartbeatService.Raise(s => s.SlowTick += null, EventArgs.Empty); _BaseStationDatabase.Verify(d => d.UpdateFlight(It.IsAny<BaseStationFlight>()), Times.Once()); // Note that the totals are not null after the final update even if no messages were received in a particular category Assert.AreEqual(worksheet.Int("NumPosMsgRec"), flight.NumPosMsgRec.Value); Assert.AreEqual(worksheet.Int("NumADSBMsgRec"), flight.NumADSBMsgRec.Value); Assert.AreEqual(worksheet.Int("NumModeSMsgRec"), flight.NumModeSMsgRec.Value); Assert.AreEqual(worksheet.Int("NumIDMsgRec"), flight.NumIDMsgRec.Value); Assert.AreEqual(worksheet.Int("NumSurPosMsgRec"), flight.NumSurPosMsgRec.Value); Assert.AreEqual(worksheet.Int("NumAirPosMsgRec"), flight.NumAirPosMsgRec.Value); Assert.AreEqual(worksheet.Int("NumAirVelMsgRec"), flight.NumAirVelMsgRec.Value); Assert.AreEqual(worksheet.Int("NumSurAltMsgRec"), flight.NumSurAltMsgRec.Value); Assert.AreEqual(worksheet.Int("NumSurIDMsgRec"), flight.NumSurIDMsgRec.Value); Assert.AreEqual(worksheet.Int("NumAirToAirMsgRec"), flight.NumAirToAirMsgRec.Value); Assert.AreEqual(worksheet.Int("NumAirCallRepMsgRec"), flight.NumAirCallRepMsgRec.Value); }
public void BaseStationMessageCompressor_Compress_And_Decompress_Work_As_Expected() { ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext); var messageIn = new BaseStationMessage(); messageIn.MessageType = worksheet.ParseEnum <BaseStationMessageType>("MessageType"); messageIn.TransmissionType = worksheet.ParseEnum <BaseStationTransmissionType>("TransmissionType"); messageIn.StatusCode = worksheet.ParseEnum <BaseStationStatusCode>("StatusCode"); messageIn.Icao24 = worksheet.EString("Icao24"); messageIn.SessionId = worksheet.Int("SessionId"); messageIn.AircraftId = worksheet.Int("AircraftId"); messageIn.FlightId = worksheet.Int("FlightId"); messageIn.MessageGenerated = worksheet.DateTime("MessageGenerated"); messageIn.MessageLogged = worksheet.DateTime("MessageLogged"); messageIn.Callsign = worksheet.String("Callsign"); messageIn.Altitude = worksheet.NInt("Altitude"); messageIn.GroundSpeed = worksheet.NInt("GroundSpeed"); messageIn.Track = worksheet.NFloat("Track"); messageIn.Latitude = worksheet.NDouble("Latitude"); messageIn.Longitude = worksheet.NDouble("Longitude"); messageIn.VerticalRate = worksheet.NInt("VerticalRate"); messageIn.Squawk = worksheet.NInt("Squawk"); messageIn.SquawkHasChanged = worksheet.NBool("SquawkHasChanged"); messageIn.Emergency = worksheet.NBool("Emergency"); messageIn.IdentActive = worksheet.NBool("IdentActive"); messageIn.OnGround = worksheet.NBool("OnGround"); int expectedLength = worksheet.Int("Length"); byte[] bytes = _Compressor.Compress(messageIn); Assert.AreEqual(expectedLength, bytes.Length); DateTime earliestDate = DateTime.Now; BaseStationMessage messageOut = _Compressor.Decompress(bytes); DateTime latestDate = DateTime.Now; if (bytes.Length == 0) { Assert.IsNull(messageOut); } else { Assert.AreEqual(messageIn.MessageType, messageOut.MessageType); Assert.AreEqual(messageIn.TransmissionType, messageOut.TransmissionType); Assert.AreEqual(BaseStationStatusCode.None, messageOut.StatusCode); Assert.AreEqual(messageIn.Icao24, messageOut.Icao24); Assert.AreEqual(0, messageOut.SessionId); Assert.AreEqual(0, messageOut.AircraftId); Assert.AreEqual(0, messageOut.FlightId); Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageGenerated.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks); Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageLogged.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks); Assert.AreEqual(messageIn.Callsign, messageOut.Callsign); Assert.AreEqual(messageIn.Altitude, messageOut.Altitude); Assert.AreEqual(messageIn.GroundSpeed, messageOut.GroundSpeed); Assert.AreEqual(messageIn.Track, messageOut.Track); if (messageIn.Latitude == null) { Assert.IsNull(messageOut.Latitude); } else { Assert.AreEqual(messageIn.Latitude.Value, messageOut.Latitude.Value, 0.000001); } if (messageIn.Longitude == null) { Assert.IsNull(messageOut.Longitude); } else { Assert.AreEqual(messageIn.Longitude.Value, messageOut.Longitude.Value, 0.000001); } Assert.AreEqual(messageIn.VerticalRate, messageOut.VerticalRate); Assert.AreEqual(messageIn.Squawk, messageOut.Squawk); Assert.AreEqual(messageIn.SquawkHasChanged, messageOut.SquawkHasChanged); Assert.AreEqual(messageIn.Emergency, messageOut.Emergency); Assert.AreEqual(messageIn.IdentActive, messageOut.IdentActive); Assert.AreEqual(messageIn.OnGround, messageOut.OnGround); } }
private void Do_BaseStationMessage_ToBaseStationString_Builds_Valid_BaseStation_Messages_From_A_BaseStationMessage_Object() { var worksheet = new ExcelWorksheetData(TestContext); _Implementation.MessageType = worksheet.ParseEnum<BaseStationMessageType>("MessageType"); _Implementation.TransmissionType = worksheet.ParseEnum<BaseStationTransmissionType>("TransmissionType"); _Implementation.StatusCode = worksheet.ParseEnum<BaseStationStatusCode>("StatusCode"); _Implementation.SessionId = worksheet.Int("SessionId"); _Implementation.AircraftId = worksheet.Int("AircraftId"); _Implementation.Icao24 = worksheet.String("Icao24"); _Implementation.FlightId = worksheet.Int("FlightId"); _Implementation.MessageGenerated = worksheet.DateTime("MessageGenerated"); _Implementation.MessageLogged = worksheet.DateTime("MessageLogged"); _Implementation.Callsign = worksheet.String("Callsign"); _Implementation.Altitude = worksheet.NInt("Altitude"); _Implementation.GroundSpeed = worksheet.NFloat("GroundSpeed"); _Implementation.Track = worksheet.NFloat("Track"); _Implementation.Latitude = worksheet.NDouble("Latitude"); _Implementation.Longitude = worksheet.NDouble("Longitude"); _Implementation.VerticalRate = worksheet.NInt("VerticalRate"); _Implementation.Squawk = worksheet.NInt("Squawk"); _Implementation.SquawkHasChanged = worksheet.NBool("SquawkHasChanged"); _Implementation.Emergency = worksheet.NBool("Emergency"); _Implementation.IdentActive = worksheet.NBool("IdentActive"); _Implementation.OnGround = worksheet.NBool("OnGround"); Assert.AreEqual(worksheet.String("Text"), _Implementation.ToBaseStationString()); }
public void FlightSimulatorXPresenter_RidingAircraft_Sends_Real_World_Aircraft_Information_To_FSX_On_View_Timer_Tick() { var worksheet = new ExcelWorksheetData(TestContext); _Presenter.Initialise(_View.Object); _Provider.Setup(p => p.UtcNow).Returns(worksheet.DateTime("UtcNow")); _SelectedAircraft.UniqueId = 92; var aircraft = new Mock<IAircraft>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _RealAircraftList.Add(aircraft.Object); aircraft.Object.UniqueId = 92; aircraft.Object.Latitude = worksheet.NFloat("Latitude"); aircraft.Object.Longitude = worksheet.NFloat("Longitude"); aircraft.Object.PositionTime = worksheet.NDateTime("PositionTime"); aircraft.Object.GroundSpeed = worksheet.NFloat("GroundSpeed"); aircraft.Object.Track = worksheet.NFloat("Track"); aircraft.Object.Type = worksheet.String("Type"); aircraft.Object.Model = worksheet.String("Model"); aircraft.Object.Operator = worksheet.String("Operator"); aircraft.Object.Registration = worksheet.String("Registration"); aircraft.Object.Squawk = worksheet.NInt("Squawk"); aircraft.Object.Altitude = worksheet.NInt("Altitude"); aircraft.Object.VerticalRate = worksheet.NInt("VerticalRate"); WriteAircraftInformation aircraftInformation = new WriteAircraftInformation(); _FlightSimulatorX.Setup(f => f.MoveAircraft(It.IsAny<WriteAircraftInformation>())).Callback((WriteAircraftInformation writeAircraftInformation) => { aircraftInformation = writeAircraftInformation; }); _FlightSimulatorX.Setup(f => f.Connected).Returns(true); _FlightSimulatorX.Raise(f => f.ConnectionStatusChanged += null, EventArgs.Empty); _View.Raise(v => v.RideAircraftClicked += null, EventArgs.Empty); _View.Raise(v => v.RefreshFlightSimulatorXInformation += null, EventArgs.Empty); _FlightSimulatorX.Verify(f => f.MoveAircraft(It.IsAny<WriteAircraftInformation>()), Times.Once()); Assert.AreEqual(worksheet.Double("FSXAirspeedIndicated"), aircraftInformation.AirspeedIndicated); Assert.AreEqual(worksheet.Double("FSXAltitude"), aircraftInformation.Altitude); Assert.AreEqual(worksheet.Double("FSXLatitude"), aircraftInformation.Latitude, 0.001); Assert.AreEqual(worksheet.Double("FSXLongitude"), aircraftInformation.Longitude, 0.001); Assert.AreEqual(worksheet.String("FSXOperator"), aircraftInformation.Operator); Assert.AreEqual(worksheet.String("FSXRegistration"), aircraftInformation.Registration); Assert.AreEqual(worksheet.Double("FSXTrueHeading"), aircraftInformation.TrueHeading, 0.001); Assert.AreEqual(worksheet.Double("FSXVerticalSpeed"), aircraftInformation.VerticalSpeed); }
public void BaseStationMessageTranslator_Translate_Translates_Messages_Correctly() { ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext); BaseStationMessage translated = _Implementation.Translate(worksheet.String("Text")); Assert.AreEqual(Enum.Parse(typeof(BaseStationMessageType), worksheet.String("MessageType")), translated.MessageType); Assert.AreEqual(Enum.Parse(typeof(BaseStationTransmissionType), worksheet.String("TransmissionType")), translated.TransmissionType); Assert.AreEqual(Enum.Parse(typeof(BaseStationStatusCode), worksheet.String("StatusCode")), translated.StatusCode); Assert.AreEqual(worksheet.Int("SessionId"), translated.SessionId); Assert.AreEqual(worksheet.Int("AircraftId"), translated.AircraftId); Assert.AreEqual(worksheet.String("Icao24"), translated.Icao24); Assert.AreEqual(worksheet.Int("FlightId"), translated.FlightId); Assert.AreEqual(worksheet.DateTime("MessageGenerated"), translated.MessageGenerated); Assert.AreEqual(worksheet.DateTime("MessageLogged"), translated.MessageLogged); Assert.AreEqual(worksheet.String("Callsign"), translated.Callsign); Assert.AreEqual(worksheet.NFloat("Altitude"), translated.Altitude); Assert.AreEqual(worksheet.NFloat("GroundSpeed"), translated.GroundSpeed); Assert.AreEqual(worksheet.NFloat("Track"), translated.Track); Assert.AreEqual(worksheet.NDouble("Latitude"), translated.Latitude); Assert.AreEqual(worksheet.NDouble("Longitude"), translated.Longitude); Assert.AreEqual(worksheet.NFloat("VerticalRate"), translated.VerticalRate); Assert.AreEqual(worksheet.NInt("Squawk"), translated.Squawk); Assert.AreEqual(worksheet.NBool("SquawkHasChanged"), translated.SquawkHasChanged); Assert.AreEqual(worksheet.NBool("Emergency"), translated.Emergency); Assert.AreEqual(worksheet.NBool("IdentActive"), translated.IdentActive); Assert.AreEqual(worksheet.NBool("OnGround"), translated.OnGround); }
public void AdsbTranslator_Translate_Decodes_Messages_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); var expectedValue = new SpreadsheetFieldValue(worksheet, 17); var bits = worksheet.String("ExtendedSquitterMessage"); var bytes = TestUtilities.ConvertBitStringToBytes(bits); var df = worksheet.String("DF"); int countTestsPerformed = 0; for(var modeSDownlinkFormats = 0;modeSDownlinkFormats < 5;++modeSDownlinkFormats) { DownlinkFormat downlinkFormat = DownlinkFormat.ShortAirToAirSurveillance; ControlField? controlField = null; ApplicationField? applicationField = null; switch(modeSDownlinkFormats) { case 0: downlinkFormat = DownlinkFormat.ExtendedSquitter; break; case 1: downlinkFormat = DownlinkFormat.ExtendedSquitterNonTransponder; controlField = ControlField.AdsbDeviceTransmittingIcao24; break; case 2: downlinkFormat = DownlinkFormat.ExtendedSquitterNonTransponder; controlField = ControlField.AdsbDeviceNotTransmittingIcao24; break; case 3: downlinkFormat = DownlinkFormat.ExtendedSquitterNonTransponder; controlField = ControlField.AdsbRebroadcastOfExtendedSquitter; break; case 4: downlinkFormat = DownlinkFormat.MilitaryExtendedSquitter; applicationField = ApplicationField.ADSB; break; } if(df != "ALL") { if((int)downlinkFormat != worksheet.Int("DF")) continue; if((int?)controlField != worksheet.NInt("CF")) continue; if((int?)applicationField != worksheet.NInt("AF")) continue; } ++countTestsPerformed; TestCleanup(); TestInitialise(); _ModeSMessage.DownlinkFormat = downlinkFormat; _ModeSMessage.ControlField = controlField; _ModeSMessage.ApplicationField = applicationField; _ModeSMessage.ExtendedSquitterMessage = bytes.ToArray(); var message = _Translator.Translate(_ModeSMessage); var failMessage = String.Format("Failed for DF:{0} CF:{1} AF:{2}", (int)_ModeSMessage.DownlinkFormat, (int?)_ModeSMessage.ControlField, (int?)_ModeSMessage.ApplicationField); var countMessageObjects = 0; object subMessage = null; if(message.AirbornePosition != null) { ++countMessageObjects; subMessage = message.AirbornePosition; } if(message.SurfacePosition != null) { ++countMessageObjects; subMessage = message.SurfacePosition; } if(message.IdentifierAndCategory != null) { ++countMessageObjects; subMessage = message.IdentifierAndCategory; } if(message.AirborneVelocity != null) { ++countMessageObjects; subMessage = message.AirborneVelocity; } if(message.AircraftStatus != null) { ++countMessageObjects; subMessage = message.AircraftStatus; } if(message.TargetStateAndStatus != null) { ++countMessageObjects; subMessage = message.TargetStateAndStatus; } if(message.AircraftOperationalStatus != null) { ++countMessageObjects; subMessage = message.AircraftOperationalStatus; } Assert.AreEqual(1, countMessageObjects, failMessage); // Extract values that can appear on more than one message type CompactPositionReportingCoordinate cpr = null; bool? posTime = null; EmergencyState? emergencyState = null; byte? nacP = null; bool? nicBaro = null; byte? sil = null; bool? silSupplement = null; bool? isRebroadcast = null; if(message.AirbornePosition != null) { cpr = message.AirbornePosition.CompactPosition; posTime = message.AirbornePosition.PositionTimeIsExact; } else if(message.SurfacePosition != null) { cpr = message.SurfacePosition.CompactPosition; posTime = message.SurfacePosition.PositionTimeIsExact; } else if(message.AircraftStatus != null && message.AircraftStatus.EmergencyStatus != null) { emergencyState = message.AircraftStatus.EmergencyStatus.EmergencyState; } else if(message.TargetStateAndStatus != null && message.TargetStateAndStatus.Version1 != null) { nacP = message.TargetStateAndStatus.Version1.NacP; nicBaro = message.TargetStateAndStatus.Version1.NicBaro; sil = message.TargetStateAndStatus.Version1.Sil; emergencyState = message.TargetStateAndStatus.Version1.EmergencyState; } else if(message.TargetStateAndStatus != null && message.TargetStateAndStatus.Version2 != null) { nacP = message.TargetStateAndStatus.Version2.NacP; nicBaro = message.TargetStateAndStatus.Version2.NicBaro; sil = message.TargetStateAndStatus.Version2.Sil; silSupplement = message.TargetStateAndStatus.Version2.SilSupplement; isRebroadcast = message.TargetStateAndStatus.Version2.IsRebroadcast; } else if(message.AircraftOperationalStatus != null) { nacP = message.AircraftOperationalStatus.NacP; nicBaro = message.AircraftOperationalStatus.NicBaro; sil = message.AircraftOperationalStatus.Sil; silSupplement = message.AircraftOperationalStatus.SilSupplement; isRebroadcast = message.AircraftOperationalStatus.IsRebroadcast; } // Extract the full list of properties to check var checkProperties = message.GetType().GetProperties().AsQueryable(); checkProperties = checkProperties.Concat(subMessage.GetType().GetProperties()); if(message.AircraftStatus != null) { switch(message.AircraftStatus.AircraftStatusType) { case AircraftStatusType.EmergencyStatus: checkProperties = checkProperties.Concat(message.AircraftStatus.EmergencyStatus.GetType().GetProperties()); break; case AircraftStatusType.TcasResolutionAdvisoryBroadcast: checkProperties = checkProperties.Concat(message.AircraftStatus.TcasResolutionAdvisory.GetType().GetProperties()); break; } } if(message.TargetStateAndStatus != null) { switch(message.TargetStateAndStatus.TargetStateAndStatusType) { case TargetStateAndStatusType.Version1: checkProperties = checkProperties.Concat(message.TargetStateAndStatus.Version1.GetType().GetProperties()); break; case TargetStateAndStatusType.Version2: checkProperties = checkProperties.Concat(message.TargetStateAndStatus.Version2.GetType().GetProperties()); break; } } Assert.IsNotNull(message, failMessage); foreach(var messageProperty in checkProperties) { switch(messageProperty.Name) { case "AdsbVersion": Assert.AreEqual(expectedValue.GetNByte("V"), message.AircraftOperationalStatus.AdsbVersion, failMessage); break; case "AirborneCapability": Assert.AreEqual(expectedValue.GetNInt("AC", true), (int?)message.AircraftOperationalStatus.AirborneCapability, failMessage); break; case "AirbornePosition": break; case "AirborneVelocity": break; case "AircraftOperationalStatus": break; case "AircraftOperationalStatusType": Assert.AreEqual(expectedValue.GetEnum<AircraftOperationalStatusType>("AST"), message.AircraftOperationalStatus.AircraftOperationalStatusType, failMessage); break; case "AircraftStatus": break; case "AircraftStatusType": Assert.AreEqual(expectedValue.GetEnum<AircraftStatusType>("AST"), message.AircraftStatus.AircraftStatusType, failMessage); break; case "Airspeed": Assert.AreEqual(expectedValue.GetNDouble("AS"), message.AirborneVelocity.Airspeed, failMessage); break; case "AirspeedExceeded": Assert.AreEqual(expectedValue.GetNBool("AS:M"), message.AirborneVelocity.AirspeedExceeded, failMessage); break; case "AirspeedIsTrueAirspeed": Assert.AreEqual(expectedValue.GetNBool("AST"), message.AirborneVelocity.AirspeedIsTrueAirspeed, failMessage); break; case "AltitudesAreMeanSeaLevel": Assert.AreEqual(expectedValue.GetNBool("VMSL"), message.TargetStateAndStatus.Version1.AltitudesAreMeanSeaLevel, failMessage); break; case "BarometricAltitude": Assert.AreEqual(expectedValue.GetNInt("BA"), message.AirbornePosition.BarometricAltitude, failMessage); break; case "BarometricPressureSetting": Assert.AreEqual(expectedValue.GetNFloat("QNH"), message.TargetStateAndStatus.Version2.BarometricPressureSetting, failMessage); break; case "ChangeOfIntent": Assert.AreEqual(expectedValue.GetNBool("IC"), message.AirborneVelocity.ChangeOfIntent, failMessage); break; case "CompactPosition": Assert.AreEqual(expectedValue.GetString("CPR"), cpr == null ? null : cpr.ToString(), failMessage); break; case "EmergencyState": Assert.AreEqual(expectedValue.GetEnum<EmergencyState>("ES"), emergencyState, failMessage); break; case "EmergencyStatus": if(message.AircraftStatus.AircraftStatusType != AircraftStatusType.EmergencyStatus) Assert.IsNull(message.AircraftStatus.EmergencyStatus); break; case "EmitterCategory": Assert.AreEqual(GetExpectedEmitterCategory(expectedValue), message.IdentifierAndCategory.EmitterCategory, failMessage); break; case "FormattedThreatIcao24": break; case "GeometricAltitude": Assert.AreEqual(expectedValue.GetNInt("GA"), message.AirbornePosition.GeometricAltitude, failMessage); break; case "GeometricAltitudeDelta": Assert.AreEqual(expectedValue.GetNShort("DBA"), message.AirborneVelocity.GeometricAltitudeDelta, failMessage); break; case "GeometricAltitudeDeltaExceeded": Assert.AreEqual(expectedValue.GetNBool("DBA:M"), message.AirborneVelocity.GeometricAltitudeDeltaExceeded, failMessage); break; case "GroundSpeed": Assert.AreEqual(expectedValue.GetNDouble("GSPD"), message.SurfacePosition.GroundSpeed, failMessage); break; case "GroundSpeedExceeded": Assert.AreEqual(expectedValue.GetNBool("GSPD:M"), message.SurfacePosition.GroundSpeedExceeded, failMessage); break; case "GroundTrack": Assert.AreEqual(expectedValue.GetNDouble("GTRK"), message.SurfacePosition.GroundTrack, failMessage); break; case "Gva": Assert.AreEqual(expectedValue.GetNByte("GVA"), message.AircraftOperationalStatus.Gva, failMessage); break; case "Heading": Assert.AreEqual(expectedValue.GetNDouble("HDG"), message.AirborneVelocity.Heading, failMessage); break; case "HorizontalDataSource": Assert.AreEqual(expectedValue.GetEnum<HorizontalDataSource>("HDS"), message.TargetStateAndStatus.Version1.HorizontalDataSource, failMessage); break; case "HorizontalModeIndicator": Assert.AreEqual(expectedValue.GetEnum<HorizontalModeIndicator>("HMI"), message.TargetStateAndStatus.Version1.HorizontalModeIndicator, failMessage); break; case "HorizontalReferenceIsMagneticNorth": Assert.AreEqual(expectedValue.GetNBool("HRD"), message.AircraftOperationalStatus.HorizontalReferenceIsMagneticNorth, failMessage); break; case "HorizontalVelocityError": Assert.AreEqual(expectedValue.GetNFloat("NAC"), message.AirborneVelocity.HorizontalVelocityError, failMessage); break; case "Identification": Assert.AreEqual(expectedValue.GetString("ID"), message.IdentifierAndCategory.Identification, failMessage); break; case "IdentifierAndCategory": break; case "IsAltitudeHoldActive": Assert.AreEqual(expectedValue.GetNBool("ALTH"), message.TargetStateAndStatus.Version2.IsAltitudeHoldActive, failMessage); break; case "IsApproachModeActive": Assert.AreEqual(expectedValue.GetNBool("APP"), message.TargetStateAndStatus.Version2.IsApproachModeActive, failMessage); break; case "IsAutopilotEngaged": Assert.AreEqual(expectedValue.GetNBool("APE"), message.TargetStateAndStatus.Version2.IsAutopilotEngaged, failMessage); break; case "IsLnavEngaged": Assert.AreEqual(expectedValue.GetNBool("LNAV"), message.TargetStateAndStatus.Version2.IsLnavEngaged, failMessage); break; case "IsRebroadcast": Assert.AreEqual(expectedValue.GetNBool("ADSR"), isRebroadcast, failMessage); break; case "IsReversing": Assert.AreEqual(expectedValue.GetNBool("REV"), message.SurfacePosition.IsReversing, failMessage); break; case "IsTcasOperational": Assert.AreEqual(expectedValue.GetNBool("TCOP"), message.TargetStateAndStatus.Version2.IsTcasOperational, failMessage); break; case "IsVnavEngaged": Assert.AreEqual(expectedValue.GetNBool("VNAV"), message.TargetStateAndStatus.Version2.IsVnavEngaged, failMessage); break; case "LateralAxisGpsOffset": Assert.AreEqual(expectedValue.GetNShort("GLAT"), message.AircraftOperationalStatus.LateralAxisGpsOffset, failMessage); break; case "LongitudinalAxisGpsOffset": Assert.AreEqual(expectedValue.GetNByte("GLNG"), message.AircraftOperationalStatus.LongitudinalAxisGpsOffset, failMessage); break; case "MaximumLength": Assert.AreEqual(expectedValue.GetNFloat("MLN"), message.AircraftOperationalStatus.MaximumLength, failMessage); break; case "MaximumWidth": Assert.AreEqual(expectedValue.GetNFloat("MWD"), message.AircraftOperationalStatus.MaximumWidth, failMessage); break; case "MessageFormat": Assert.AreEqual(worksheet.ParseEnum<MessageFormat>("MessageFormat"), message.MessageFormat, failMessage); break; case "ModeSMessage": Assert.AreSame(_ModeSMessage, message.ModeSMessage, failMessage); break; case "MultipleThreatEncounter": Assert.AreEqual(expectedValue.GetNBool("MTE"), message.AircraftStatus.TcasResolutionAdvisory.MultipleThreatEncounter, failMessage); break; case "MultipleThreatResolutionAdvisory": Assert.AreEqual(expectedValue.GetNShort("ARA-M", true), (short?)message.AircraftStatus.TcasResolutionAdvisory.MultipleThreatResolutionAdvisory, failMessage); break; case "NacP": Assert.AreEqual(expectedValue.GetNByte("NACP"), nacP, failMessage); break; case "NicA": Assert.AreEqual(expectedValue.GetNByte("NICA"), message.AircraftOperationalStatus.NicA, failMessage); break; case "NicB": Assert.AreEqual(expectedValue.GetNByte("NICB"), message.AirbornePosition.NicB, failMessage); break; case "NicC": Assert.AreEqual(expectedValue.GetNByte("NICC"), message.AircraftOperationalStatus.NicC, failMessage); break; case "NicBaro": Assert.AreEqual(expectedValue.GetNBool("NICBA"), nicBaro, failMessage); break; case "OperationalMode": Assert.AreEqual(expectedValue.GetNInt("OM", true), (int?)message.AircraftOperationalStatus.OperationalMode, failMessage); break; case "PositionTimeIsExact": Assert.AreEqual(expectedValue.GetNBool("TI"), posTime, failMessage); break; case "ResolutionAdvisoryComplement": Assert.AreEqual(expectedValue.GetNByte("RAC", true), (byte?)message.AircraftStatus.TcasResolutionAdvisory.ResolutionAdvisoryComplement, failMessage); break; case "ResolutionAdvisoryTerminated": Assert.AreEqual(expectedValue.GetNBool("RAT"), message.AircraftStatus.TcasResolutionAdvisory.ResolutionAdvisoryTerminated, failMessage); break; case "SelectedAltitude": Assert.AreEqual(expectedValue.GetNInt("ALT"), message.TargetStateAndStatus.Version2.SelectedAltitude, failMessage); break; case "SelectedAltitudeIsFms": Assert.AreEqual(expectedValue.GetNBool("ALTF"), message.TargetStateAndStatus.Version2.SelectedAltitudeIsFms, failMessage); break; case "SelectedHeading": Assert.AreEqual(expectedValue.GetNDouble("HDG"), message.TargetStateAndStatus.Version2.SelectedHeading, failMessage); break; case "Sil": Assert.AreEqual(expectedValue.GetNByte("SIL"), sil, failMessage); break; case "SilSupplement": Assert.AreEqual(expectedValue.GetNBool("SILP"), silSupplement, failMessage); break; case "SingleThreatResolutionAdvisory": Assert.AreEqual(expectedValue.GetNShort("ARA-S", true), (short?)message.AircraftStatus.TcasResolutionAdvisory.SingleThreatResolutionAdvisory, failMessage); break; case "Squawk": Assert.AreEqual(expectedValue.GetNShort("SQK"), message.AircraftStatus.EmergencyStatus.Squawk, failMessage); break; case "SurfacePositionAngleIsTrack": Assert.AreEqual(expectedValue.GetNBool("SPT"), message.AircraftOperationalStatus.SurfacePositionAngleIsTrack, failMessage); break; case "SurfaceCapability": Assert.AreEqual(expectedValue.GetNInt("SC", true), (int?)message.AircraftOperationalStatus.SurfaceCapability, failMessage); break; case "SurfacePosition": break; case "SurveillanceStatus": Assert.AreEqual(expectedValue.GetEnum<SurveillanceStatus>("SS"), message.AirbornePosition.SurveillanceStatus, failMessage); break; case "SystemDesignAssurance": Assert.AreEqual(expectedValue.GetEnum<SystemDesignAssurance>("SDA"), message.AircraftOperationalStatus.SystemDesignAssurance, failMessage); break; case "TargetAltitude": Assert.AreEqual(expectedValue.GetNInt("ALT"), message.TargetStateAndStatus.Version1.TargetAltitude, failMessage); break; case "TargetAltitudeCapability": Assert.AreEqual(expectedValue.GetEnum<TargetAltitudeCapability>("TAC"), message.TargetStateAndStatus.Version1.TargetAltitudeCapability, failMessage); break; case "TargetHeading": Assert.AreEqual(expectedValue.GetNShort("HDG"), message.TargetStateAndStatus.Version1.TargetHeading, failMessage); break; case "TargetHeadingIsTrack": Assert.AreEqual(expectedValue.GetNBool("HDG-T"), message.TargetStateAndStatus.Version1.TargetHeadingIsTrack, failMessage); break; case "TargetStateAndStatus": break; case "TargetStateAndStatusType": Assert.AreEqual(expectedValue.GetEnum<TargetStateAndStatusType>("TST"), message.TargetStateAndStatus.TargetStateAndStatusType, failMessage); break; case "TcasCapabilityMode": Assert.AreEqual(expectedValue.GetEnum<TcasCapabilityMode>("TCC"), message.TargetStateAndStatus.Version1.TcasCapabilityMode, failMessage); break; case "TcasResolutionAdvisory": if(message.AircraftStatus.AircraftStatusType != AircraftStatusType.TcasResolutionAdvisoryBroadcast) Assert.IsNull(message.AircraftStatus.TcasResolutionAdvisory); break; case "ThreatAltitude": Assert.AreEqual(expectedValue.GetNInt("TID-A"), message.AircraftStatus.TcasResolutionAdvisory.ThreatAltitude, failMessage); break; case "ThreatBearing": Assert.AreEqual(expectedValue.GetNShort("TID-B"), message.AircraftStatus.TcasResolutionAdvisory.ThreatBearing, failMessage); break; case "ThreatIcao24": Assert.AreEqual(expectedValue.GetNInt("TID", true), message.AircraftStatus.TcasResolutionAdvisory.ThreatIcao24, failMessage); break; case "ThreatRange": Assert.AreEqual(expectedValue.GetNFloat("TID-R"), message.AircraftStatus.TcasResolutionAdvisory.ThreatRange, failMessage); break; case "ThreatRangeExceeded": Assert.AreEqual(expectedValue.GetNBool("TID-R:M"), message.AircraftStatus.TcasResolutionAdvisory.ThreatRangeExceeded, failMessage); break; case "Type": Assert.AreEqual(worksheet.Byte("Type"), message.Type, failMessage); break; case "VectorVelocity": Assert.AreEqual(expectedValue.GetString("VV"), message.AirborneVelocity.VectorVelocity == null ? null : message.AirborneVelocity.VectorVelocity.ToString(), failMessage); break; case "VelocityType": Assert.AreEqual(expectedValue.GetEnum<VelocityType>("VT"), message.AirborneVelocity.VelocityType, failMessage); break; case "Version1": if(message.TargetStateAndStatus.TargetStateAndStatusType != TargetStateAndStatusType.Version1) Assert.IsNull(message.TargetStateAndStatus.Version1); break; case "Version2": if(message.TargetStateAndStatus.TargetStateAndStatusType != TargetStateAndStatusType.Version2) Assert.IsNull(message.TargetStateAndStatus.Version2); break; case "VerticalDataSource": Assert.AreEqual(expectedValue.GetEnum<VerticalDataSource>("VDS"), message.TargetStateAndStatus.Version1.VerticalDataSource, failMessage); break; case "VerticalModeIndicator": Assert.AreEqual(expectedValue.GetEnum<VerticalModeIndicator>("VMI"), message.TargetStateAndStatus.Version1.VerticalModeIndicator, failMessage); break; case "VerticalRate": Assert.AreEqual(expectedValue.GetNInt("VSI"), message.AirborneVelocity.VerticalRate, failMessage); break; case "VerticalRateExceeded": Assert.AreEqual(expectedValue.GetNBool("VSI:M"), message.AirborneVelocity.VerticalRateExceeded, failMessage); break; case "VerticalRateIsBarometric": Assert.AreEqual(expectedValue.GetNBool("SBV"), message.AirborneVelocity.VerticalRateIsBarometric, failMessage); break; default: Assert.Fail("Code needs to be added to check the {0} property", messageProperty.Name); break; } } } Assert.AreNotEqual(0, countTestsPerformed, "DF{0}/CF{1}/AF{2} is not valid, no tests were performed", worksheet.String("DF"), worksheet.String("CF"), worksheet.String("AF")); }
public void BaseStationMessageCompressor_Compress_And_Decompress_Work_As_Expected() { ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext); var messageIn = new BaseStationMessage(); messageIn.MessageType = worksheet.ParseEnum<BaseStationMessageType>("MessageType"); messageIn.TransmissionType = worksheet.ParseEnum<BaseStationTransmissionType>("TransmissionType"); messageIn.StatusCode = worksheet.ParseEnum<BaseStationStatusCode>("StatusCode"); messageIn.Icao24 = worksheet.EString("Icao24"); messageIn.SessionId = worksheet.Int("SessionId"); messageIn.AircraftId = worksheet.Int("AircraftId"); messageIn.FlightId = worksheet.Int("FlightId"); messageIn.MessageGenerated = worksheet.DateTime("MessageGenerated"); messageIn.MessageLogged = worksheet.DateTime("MessageLogged"); messageIn.Callsign = worksheet.String("Callsign"); messageIn.Altitude = worksheet.NInt("Altitude"); messageIn.GroundSpeed = worksheet.NInt("GroundSpeed"); messageIn.Track = worksheet.NFloat("Track"); messageIn.Latitude = worksheet.NDouble("Latitude"); messageIn.Longitude = worksheet.NDouble("Longitude"); messageIn.VerticalRate = worksheet.NInt("VerticalRate"); messageIn.Squawk = worksheet.NInt("Squawk"); messageIn.SquawkHasChanged = worksheet.NBool("SquawkHasChanged"); messageIn.Emergency = worksheet.NBool("Emergency"); messageIn.IdentActive = worksheet.NBool("IdentActive"); messageIn.OnGround = worksheet.NBool("OnGround"); int expectedLength = worksheet.Int("Length"); byte[] bytes = _Compressor.Compress(messageIn); Assert.AreEqual(expectedLength, bytes.Length); DateTime earliestDate = DateTime.Now; BaseStationMessage messageOut = _Compressor.Decompress(bytes); DateTime latestDate = DateTime.Now; if(bytes.Length == 0) Assert.IsNull(messageOut); else { Assert.AreEqual(messageIn.MessageType, messageOut.MessageType); Assert.AreEqual(messageIn.TransmissionType, messageOut.TransmissionType); Assert.AreEqual(BaseStationStatusCode.None, messageOut.StatusCode); Assert.AreEqual(messageIn.Icao24, messageOut.Icao24); Assert.AreEqual(0, messageOut.SessionId); Assert.AreEqual(0, messageOut.AircraftId); Assert.AreEqual(0, messageOut.FlightId); Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageGenerated.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks); Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageLogged.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks); Assert.AreEqual(messageIn.Callsign, messageOut.Callsign); Assert.AreEqual(messageIn.Altitude, messageOut.Altitude); Assert.AreEqual(messageIn.GroundSpeed, messageOut.GroundSpeed); Assert.AreEqual(messageIn.Track, messageOut.Track); if(messageIn.Latitude == null) Assert.IsNull(messageOut.Latitude); else Assert.AreEqual(messageIn.Latitude.Value, messageOut.Latitude.Value, 0.000001); if(messageIn.Longitude == null) Assert.IsNull(messageOut.Longitude); else Assert.AreEqual(messageIn.Longitude.Value, messageOut.Longitude.Value, 0.000001); Assert.AreEqual(messageIn.VerticalRate, messageOut.VerticalRate); Assert.AreEqual(messageIn.Squawk, messageOut.Squawk); Assert.AreEqual(messageIn.SquawkHasChanged, messageOut.SquawkHasChanged); Assert.AreEqual(messageIn.Emergency, messageOut.Emergency); Assert.AreEqual(messageIn.IdentActive, messageOut.IdentActive); Assert.AreEqual(messageIn.OnGround, messageOut.OnGround); } }
public void Do_ExtractMessageBytes_Extracts_Messages_From_Bytes(bool inputIsText, int blobCount, int extractedCount, Func <byte[], byte[]> alterFirstPacket = null) { var worksheet = new ExcelWorksheetData(TestContext); var comments = worksheet.String("Comments"); var input = new List <byte[]>(); for (var i = 1; i <= blobCount; ++i) { var blobColumn = String.Format("Blob{0}", i); if (worksheet.String(blobColumn) != null) { byte[] bytes; if (inputIsText) { bytes = Encoding.ASCII.GetBytes(worksheet.String(blobColumn).Replace("\\n", "\n").Replace("\\r", "\r")); } else { bytes = worksheet.Bytes(blobColumn); } if (input.Count == 0 && alterFirstPacket != null) { bytes = alterFirstPacket(bytes); } input.Add(bytes); } } var expectedOutput = new List <ExtractedBytes>(); for (var i = 1; i <= extractedCount; ++i) { var bytesColumn = String.Format("Extracted{0}", i); var parityColumn = String.Format("HadParity{0}", i); var checksumColumn = String.Format("BadChecksum{0}", i); var signalLevelColumn = String.Format("SignalLevel{0}", i); var isMlatColumn = String.Format("IsMlat{0}", i); if (worksheet.String(bytesColumn) != null || worksheet.String(checksumColumn) != null) { expectedOutput.Add(new ExtractedBytes() { Bytes = worksheet.Bytes(bytesColumn), HasParity = worksheet.Bool(parityColumn), ChecksumFailed = worksheet.Bool(checksumColumn), SignalLevel = worksheet.NInt(signalLevelColumn), IsMlat = worksheet.Bool(isMlatColumn), }); } } var output = new List <ExtractedBytes>(); foreach (var inputBytes in input) { foreach (var extractedBytes in Extractor.ExtractMessageBytes(inputBytes, 0, inputBytes.Length)) { output.Add((ExtractedBytes)extractedBytes.Clone()); } } Assert.AreEqual(expectedOutput.Count, output.Count, comments); for (var i = 0; i < expectedOutput.Count; ++i) { var expected = expectedOutput[i]; var actual = output[i]; Assert.AreEqual(Format, actual.Format); Assert.AreEqual(expected.ChecksumFailed, actual.ChecksumFailed, comments); if (!expected.ChecksumFailed) { Assert.AreEqual(expected.HasParity, actual.HasParity, comments); Assert.AreEqual(expected.SignalLevel, actual.SignalLevel, comments); Assert.AreEqual(expected.IsMlat, actual.IsMlat, comments); var actualBytes = new byte[actual.Length]; Array.Copy(actual.Bytes, actual.Offset, actualBytes, 0, actual.Length); Assert.IsTrue(expected.Bytes.SequenceEqual(actualBytes), comments); } } }