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 AccessFilter_Allow_Behaves_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); // Uncomment this block to only run tests that have True in the RunThis column //var runThis = worksheet.Bool("RunThis"); //if(!runThis) Assert.Fail(); _Access.DefaultAccess = worksheet.ParseEnum <DefaultAccess>("DefaultAccess"); for (var i = 1; i <= 2; ++i) { var addressColumnName = String.Format("Address{0}", i); var address = worksheet.EString(addressColumnName); if (address != null) { _Access.Addresses.Add(address); } else { break; } } _Filter.Initialise(_Access); var ipAddressText = worksheet.String("IPAddress"); var ipAddress = IPAddress.Parse(ipAddressText); var allow = _Filter.Allow(ipAddress); var expected = worksheet.Bool("Allow"); Assert.AreEqual(expected, allow); }
public void ConnectionSessionLogPresenter_Clicking_ShowSessions_Triggers_Validation() { var worksheet = new ExcelWorksheetData(TestContext); _Presenter.Initialise(_View.Object); _View.Object.StartDate = worksheet.DateTime("StartDate"); _View.Object.EndDate = worksheet.DateTime("EndDate"); ValidationResults validationResults = null; _View.Setup(v => v.ShowValidationResults(It.IsAny <ValidationResults>())).Callback((ValidationResults results) => { validationResults = results; }); _View.Raise(v => v.ShowSessionsClicked += null, EventArgs.Empty); Assert.IsNotNull(validationResults); Assert.AreEqual(worksheet.Int("CountErrors"), validationResults.Results.Count()); if (validationResults.Results.Count() > 0) { Assert.IsTrue(validationResults.Results.Where(r => r.Field == worksheet.ParseEnum <ValidationField>("Field") && r.Message == worksheet.String("Message") && r.IsWarning == worksheet.Bool("IsWarning")).Any()); } }
public void MimeType_GetContentClassification_Returns_Correct_Content_Classification_For_Mime_Type() { var worksheet = new ExcelWorksheetData(TestContext); var mimeType = worksheet.EString("MimeType"); var classification = worksheet.ParseEnum <ContentClassification>("Classification"); Assert.AreEqual(classification, MimeType.GetContentClassification(mimeType)); }
public void StandingDataManager_FindAircraftType_Returns_Correct_Values() { ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext); _Implementation.Load(); var searchFor = worksheet.String("SearchFor"); var aircraftType = _Implementation.FindAircraftType(searchFor); if (worksheet.Bool("IsNull")) { Assert.AreEqual(null, aircraftType); } else { List <string> manufacturers = new List <string>(); List <string> models = new List <string>(); BuildExpectedList(worksheet, manufacturers, "ManOut1"); BuildExpectedList(worksheet, manufacturers, "ManOut2"); BuildExpectedList(worksheet, models, "ModelOut1"); BuildExpectedList(worksheet, models, "ModelOut2"); Assert.AreEqual(manufacturers.Count, aircraftType.Manufacturers.Count); foreach (string manufacturer in manufacturers) { Assert.IsTrue(aircraftType.Manufacturers.Contains(manufacturer)); } Assert.AreEqual(models.Count, aircraftType.Models.Count); foreach (string model in models) { Assert.IsTrue(aircraftType.Models.Contains(model)); } Assert.AreEqual(worksheet.String("Type"), aircraftType.Type); Assert.AreEqual(worksheet.ParseEnum <WakeTurbulenceCategory>("Wake"), aircraftType.WakeTurbulenceCategory); Assert.AreEqual(worksheet.ParseEnum <EngineType>("EngineType"), aircraftType.EngineType); Assert.AreEqual(worksheet.String("Engines"), aircraftType.Engines); Assert.AreEqual(worksheet.ParseEnum <Species>("Species"), aircraftType.Species); } }
public void ModeSTranslator_Translate_Decodes_Packets_Correctly() { for(var conversionMethod = 0;conversionMethod < 2;++conversionMethod) { var worksheet = new ExcelWorksheetData(TestContext); var expectedValue = new SpreadsheetFieldValue(worksheet, 7); var bits = worksheet.String("Packet"); var bytes = TestUtilities.ConvertBitStringToBytes(bits); var reply = conversionMethod == 0 ? _Translator.Translate(bytes.ToArray()) : _Translator.Translate(bytes.ToArray(), 0); foreach(var replyProperty in reply.GetType().GetProperties()) { switch(replyProperty.Name) { case "ACASMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MV"), reply.ACASMessage)); break; case "Altitude": Assert.AreEqual(expectedValue.GetNInt("AC"), reply.Altitude); break; case "AltitudeIsMetric": Assert.AreEqual(expectedValue.GetNBool("AC:M"), reply.AltitudeIsMetric); break; case "ApplicationField": Assert.AreEqual(expectedValue.GetEnum<ApplicationField>("AF"), reply.ApplicationField); break; case "Capability": Assert.AreEqual(expectedValue.GetEnum<Capability>("CA"), reply.Capability); break; case "CommBMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MB"), reply.CommBMessage)); break; case "CommDMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MD"), reply.CommDMessage)); break; case "ControlField": Assert.AreEqual(expectedValue.GetEnum<ControlField>("CF"), reply.ControlField); break; case "CrossLinkCapability": Assert.AreEqual(expectedValue.GetNBool("CC"), reply.CrossLinkCapability); break; case "DownlinkFormat": Assert.AreEqual(worksheet.ParseEnum<DownlinkFormat>("DownlinkFormat"), reply.DownlinkFormat); break; case "DownlinkRequest": Assert.AreEqual(expectedValue.GetNByte("DR", true), reply.DownlinkRequest); break; case "DSegmentNumber": Assert.AreEqual(expectedValue.GetNByte("ND", true), reply.DSegmentNumber); break; case "ElmControl": Assert.AreEqual(expectedValue.GetEnum<ElmControl>("KE"), reply.ElmControl); break; case "ExtendedSquitterMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("ME"), reply.ExtendedSquitterMessage)); break; case "ExtendedSquitterSupplementaryMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MEX"), reply.ExtendedSquitterSupplementaryMessage)); break; case "FlightStatus": Assert.AreEqual(expectedValue.GetEnum<FlightStatus>("FS"), reply.FlightStatus); break; case "FormattedIcao24": Assert.AreEqual(worksheet.String("Icao24"), reply.FormattedIcao24); break; case "Icao24": Assert.AreEqual(Convert.ToInt32(worksheet.String("Icao24"), 16), reply.Icao24); break; case "Identity": Assert.AreEqual(expectedValue.GetNShort("ID"), reply.Identity); break; case "NonIcao24Address": Assert.AreEqual(expectedValue.GetNInt("AAX", true), reply.NonIcao24Address); break; case "ParityInterrogatorIdentifier": Assert.AreEqual(expectedValue.GetNInt("PI", true), reply.ParityInterrogatorIdentifier); break; case "PossibleCallsign": Assert.AreEqual(expectedValue.GetString("PC"), reply.PossibleCallsign); break; case "ReplyInformation": Assert.AreEqual(expectedValue.GetNByte("RI", true), reply.ReplyInformation); break; case "SensitivityLevel": Assert.AreEqual(expectedValue.GetNByte("SL", true), reply.SensitivityLevel); break; case "UtilityMessage": Assert.AreEqual(expectedValue.GetNByte("UM", true), reply.UtilityMessage); break; case "VerticalStatus": Assert.AreEqual(expectedValue.GetEnum<VerticalStatus>("VS"), reply.VerticalStatus); break; default: throw new NotImplementedException(); } } } }
public void AircraftSanityChecker_CheckAltitude_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.ParseEnum <Certainty>(String.Format("Result{0}", i)); var actualResult = _Checker.CheckAltitude(1, time, altitude.Value); Assert.AreEqual(expectedResult, actualResult, String.Format("Column {0} {1}", i, comments)); } } }
private void RunDataDrivenTest(ExcelWorksheetData worksheet, Func <string, string, bool> isPathAccessible) { var defaultAccess = worksheet.ParseEnum <DefaultAccess>("DefaultAccess"); var exceptCidr1 = worksheet.String("ExceptCIDR1"); var pathFromRoot = worksheet.String("PathFromRoot"); var requestAddress = worksheet.String("RequestAddress"); var requestPathAndFile = worksheet.String("RequestPathAndFile"); var isAccessAllowed = worksheet.Bool("IsAccessAllowed"); var comments = worksheet.String("Comments"); var access = new Access() { DefaultAccess = defaultAccess, }; access.Addresses.Add(exceptCidr1); _Configuration.SetRestrictedPath(pathFromRoot, access); var result = isPathAccessible(requestPathAndFile, requestAddress); Assert.AreEqual(isAccessAllowed, result, comments); }
public void AircraftSanityChecker_CheckPosition_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 distance = worksheet.NDouble(String.Format("Distance{0}", i)); if (distance != null) { var seconds = worksheet.Double(String.Format("Seconds{0}", i)); var time = new DateTime(2014, 8, 3).AddSeconds(seconds); var expectedResult = worksheet.ParseEnum <Certainty>(String.Format("Result{0}", i)); double?latitude, longitude; GreatCircleMaths.Destination(51.0, -0.6, 90.0, distance, out latitude, out longitude); var actualResult = _Checker.CheckPosition(1, time, latitude.Value, longitude.Value); Assert.AreEqual(expectedResult, actualResult, String.Format("Column {0} {1}", i, comments)); } } }
public void ModeSTranslator_Translate_Decodes_Packets_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); var expectedValue = new SpreadsheetFieldValue(worksheet, 7); var bits = worksheet.String("Packet"); var bytes = TestUtilities.ConvertBitStringToBytes(bits); var reply = _Translator.Translate(bytes.ToArray(), 0, null, false); foreach (var replyProperty in reply.GetType().GetProperties()) { switch (replyProperty.Name) { case "ACASMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MV"), reply.ACASMessage)); break; case "Altitude": Assert.AreEqual(expectedValue.GetNInt("AC"), reply.Altitude); break; case "AltitudeIsMetric": Assert.AreEqual(expectedValue.GetNBool("AC:M"), reply.AltitudeIsMetric); break; case "ApplicationField": Assert.AreEqual(expectedValue.GetEnum <ApplicationField>("AF"), reply.ApplicationField); break; case "Capability": Assert.AreEqual(expectedValue.GetEnum <Capability>("CA"), reply.Capability); break; case "CommBMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MB"), reply.CommBMessage)); break; case "CommDMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MD"), reply.CommDMessage)); break; case "ControlField": Assert.AreEqual(expectedValue.GetEnum <ControlField>("CF"), reply.ControlField); break; case "CrossLinkCapability": Assert.AreEqual(expectedValue.GetNBool("CC"), reply.CrossLinkCapability); break; case "DownlinkFormat": Assert.AreEqual(worksheet.ParseEnum <DownlinkFormat>("DownlinkFormat"), reply.DownlinkFormat); break; case "DownlinkRequest": Assert.AreEqual(expectedValue.GetNByte("DR", true), reply.DownlinkRequest); break; case "DSegmentNumber": Assert.AreEqual(expectedValue.GetNByte("ND", true), reply.DSegmentNumber); break; case "ElmControl": Assert.AreEqual(expectedValue.GetEnum <ElmControl>("KE"), reply.ElmControl); break; case "ExtendedSquitterMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("ME"), reply.ExtendedSquitterMessage)); break; case "ExtendedSquitterSupplementaryMessage": Assert.IsTrue(TestUtilities.SequenceEqual(expectedValue.GetBytes("MEX"), reply.ExtendedSquitterSupplementaryMessage)); break; case "FlightStatus": Assert.AreEqual(expectedValue.GetEnum <FlightStatus>("FS"), reply.FlightStatus); break; case "FormattedIcao24": Assert.AreEqual(worksheet.String("Icao24"), reply.FormattedIcao24); break; case "Icao24": Assert.AreEqual(Convert.ToInt32(worksheet.String("Icao24"), 16), reply.Icao24); break; case "Identity": Assert.AreEqual(expectedValue.GetNShort("ID"), reply.Identity); break; case "IsMlat": break; case "NonIcao24Address": Assert.AreEqual(expectedValue.GetNInt("AAX", true), reply.NonIcao24Address); break; case "ParityInterrogatorIdentifier": Assert.AreEqual(expectedValue.GetNInt("PI", true), reply.ParityInterrogatorIdentifier); break; case "PossibleCallsign": Assert.AreEqual(expectedValue.GetString("PC"), reply.PossibleCallsign); break; case "ReplyInformation": Assert.AreEqual(expectedValue.GetNByte("RI", true), reply.ReplyInformation); break; case "SensitivityLevel": Assert.AreEqual(expectedValue.GetNByte("SL", true), reply.SensitivityLevel); break; case "UtilityMessage": Assert.AreEqual(expectedValue.GetNByte("UM", true), reply.UtilityMessage); break; case "VerticalStatus": Assert.AreEqual(expectedValue.GetEnum <VerticalStatus>("VS"), reply.VerticalStatus); break; case "SignalLevel": break; default: throw new NotImplementedException(); } } }
public void ConnectionSessionLogPresenter_Clicking_ShowSessions_Triggers_Validation() { var worksheet = new ExcelWorksheetData(TestContext); _Presenter.Initialise(_View.Object); _View.Object.StartDate = worksheet.DateTime("StartDate"); _View.Object.EndDate = worksheet.DateTime("EndDate"); IEnumerable<ValidationResult> validationResults = null; _View.Setup(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>())).Callback((IEnumerable<ValidationResult> results) => { validationResults = results; }); _View.Raise(v => v.ShowSessionsClicked += null, EventArgs.Empty); Assert.IsNotNull(validationResults); Assert.AreEqual(worksheet.Int("CountErrors"), validationResults.Count()); if(validationResults.Count() > 0) { Assert.IsTrue(validationResults.Where(r => r.Field == worksheet.ParseEnum<ValidationField>("Field") && r.Message == worksheet.String("Message") && r.IsWarning == worksheet.Bool("IsWarning")).Any()); } }
private void DoValidationTest(Action triggerValidation, bool doSuppressExcessiveFileSystemCheck = false) { var worksheet = new ExcelWorksheetData(TestContext); List<ValidationResult> validationResults = new List<ValidationResult>(); _View.Setup(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>())).Callback((IEnumerable<ValidationResult> results) => { foreach(var validationResult in results) validationResults.Add(validationResult); }); int countFileExistsCalls = 0; _Provider.Setup(p => p.FileExists(It.IsAny<string>())).Returns(false); _Provider.Setup(p => p.FileExists(null)).Callback(() => {throw new NullReferenceException(); }); _Provider.Setup(p => p.FileExists("FileExists")).Callback(() => countFileExistsCalls++).Returns(true); int countFolderExistsCalls = 0; _Provider.Setup(p => p.FolderExists(It.IsAny<string>())).Returns(false); _Provider.Setup(p => p.FolderExists(null)).Callback(() => {throw new NullReferenceException(); }); _Provider.Setup(p => p.FolderExists("FolderExists")).Callback(() => countFolderExistsCalls++).Returns(true); _Presenter.Initialise(_View.Object); _View.Object.BaseStationDatabaseFileName = null; _View.Object.OperatorFlagsFolder = null; _View.Object.SilhouettesFolder = null; for(var i = 1;i <= 3;++i) { var uiFieldColumn = String.Format("UIField{0}", i); var valueColumn = String.Format("Value{0}", i); if(worksheet.String(uiFieldColumn) != null) { switch(worksheet.String(uiFieldColumn)) { case "AcceptableAirborneSpeed": _View.Object.RawDecodingAcceptableAirborneSpeed = worksheet.Double(valueColumn); break; case "AcceptableAirSurfaceTransitionSpeed": _View.Object.RawDecodingAcceptableAirSurfaceTransitionSpeed = worksheet.Double(valueColumn); break; case "AcceptableSurfaceSpeed": _View.Object.RawDecodingAcceptableSurfaceSpeed = worksheet.Double(valueColumn); break; case "AcceptIcaoInNonPICount": _View.Object.AcceptIcaoInNonPICount = worksheet.Int(valueColumn); break; case "AcceptIcaoInNonPISeconds": _View.Object.AcceptIcaoInNonPISeconds = worksheet.Int(valueColumn); break; case "AcceptIcaoInPI0Count": _View.Object.AcceptIcaoInPI0Count = worksheet.Int(valueColumn); break; case "AcceptIcaoInPI0Seconds": _View.Object.AcceptIcaoInPI0Seconds = worksheet.Int(valueColumn); break; case "AirborneGlobalPositionLimit": _View.Object.RawDecodingAirborneGlobalPositionLimit = worksheet.Int(valueColumn); break; case "BaseStationAddress": _View.Object.BaseStationAddress = worksheet.EString(valueColumn); break; case "BaseStationConnectionType": _View.Object.BaseStationConnectionType = worksheet.ParseEnum<ConnectionType>(valueColumn); break; case "BaseStationPort": _View.Object.BaseStationPort = worksheet.Int(valueColumn); break; case "CheckForNewVersionsPeriodDays": _View.Object.CheckForNewVersionsPeriodDays = worksheet.Int(valueColumn); break; case "DatabaseFileName": _View.Object.BaseStationDatabaseFileName = worksheet.EString(valueColumn); break; case "DisplayTimeoutSeconds": _View.Object.DisplayTimeoutSeconds = worksheet.Int(valueColumn); break; case "FastSurfaceGlobalPositionLimit": _View.Object.RawDecodingFastSurfaceGlobalPositionLimit = worksheet.Int(valueColumn); break; case "FlagsFolder": _View.Object.OperatorFlagsFolder = worksheet.EString(valueColumn); break; case "InitialGoogleMapLatitude": _View.Object.InitialGoogleMapLatitude = worksheet.Double(valueColumn); break; case "InitialGoogleMapLongitude": _View.Object.InitialGoogleMapLongitude = worksheet.Double(valueColumn); break; case "InitialGoogleMapZoom": _View.Object.InitialGoogleMapZoom = worksheet.Int(valueColumn); break; case "InitialRefreshSeconds": _View.Object.InitialGoogleMapRefreshSeconds = worksheet.Int(valueColumn); break; case "InternetClientTimeoutMinutes": _View.Object.InternetClientTimeoutMinutes = worksheet.Int(valueColumn); break; case "MinimumRefreshSeconds": _View.Object.MinimumGoogleMapRefreshSeconds = worksheet.Int(valueColumn); break; case "PicturesFolder": _View.Object.PicturesFolder = worksheet.EString(valueColumn); break; case "ReceiverRange": _View.Object.RawDecodingReceiverRange = worksheet.Int(valueColumn); break; case "SerialBaudRate": _View.Object.SerialBaudRate = worksheet.Int(valueColumn); break; case "SerialComPort": _View.Object.SerialComPort = worksheet.EString(valueColumn); break; case "SerialDataBits": _View.Object.SerialDataBits = worksheet.Int(valueColumn); break; case "ShortTrailLengthSeconds": _View.Object.ShortTrailLengthSeconds = worksheet.Int(valueColumn); break; case "SilhouettesFolder": _View.Object.SilhouettesFolder = worksheet.EString(valueColumn); break; case "SlowSurfaceGlobalPositionLimit": _View.Object.RawDecodingSlowSurfaceGlobalPositionLimit = worksheet.Int(valueColumn); break; case "TextToSpeechSpeed": _View.Object.TextToSpeechSpeed = worksheet.Int(valueColumn); break; case "TrackingTimeoutSeconds": _View.Object.TrackingTimeoutSeconds = worksheet.Int(valueColumn); break; case "UPnpPort": _View.Object.UPnpPort = worksheet.Int(valueColumn); break; case "WebAuthenticateUser": _View.Object.WebServerUserMustAuthenticate = worksheet.Bool(valueColumn); break; case "WebUserName": _View.Object.WebServerUserName = worksheet.EString(valueColumn); break; default: throw new NotImplementedException(); } } } triggerValidation(); _View.Verify(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>()), Times.Once()); if(doSuppressExcessiveFileSystemCheck) { validationResults.Clear(); triggerValidation(); _View.Verify(v => v.ShowValidationResults(It.IsAny<IEnumerable<ValidationResult>>()), Times.Exactly(2)); Assert.IsTrue(countFileExistsCalls < 2); Assert.IsTrue(countFolderExistsCalls < 2); } var validationErrorSummary = new StringBuilder(); foreach(var validationResult in validationResults) { if(validationErrorSummary.Length != 0) validationErrorSummary.Append("; "); validationErrorSummary.AppendFormat("{0}:{1}", validationResult.Field, validationResult.Message); } Assert.AreEqual(worksheet.Int("CountErrors"), validationResults.Count(), validationErrorSummary.ToString()); if(validationResults.Count() > 0) { Assert.IsTrue(validationResults.Where(r => r.Field == worksheet.ParseEnum<ValidationField>("Field") && r.Message == worksheet.EString("Message") && r.IsWarning == worksheet.Bool("IsWarning")).Any(), validationErrorSummary.ToString()); } }
public void StandingDataManager_FindAircraftType_Returns_Correct_Values() { ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext); _Implementation.Load(); var searchFor = worksheet.String("SearchFor"); var aircraftType = _Implementation.FindAircraftType(searchFor); if(worksheet.Bool("IsNull")) Assert.AreEqual(null, aircraftType); else { List<string> manufacturers = new List<string>(); List<string> models = new List<string>(); BuildExpectedList(worksheet, manufacturers, "ManOut1"); BuildExpectedList(worksheet, manufacturers, "ManOut2"); BuildExpectedList(worksheet, models, "ModelOut1"); BuildExpectedList(worksheet, models, "ModelOut2"); Assert.AreEqual(manufacturers.Count, aircraftType.Manufacturers.Count); foreach(string manufacturer in manufacturers) Assert.IsTrue(aircraftType.Manufacturers.Contains(manufacturer)); Assert.AreEqual(models.Count, aircraftType.Models.Count); foreach(string model in models) Assert.IsTrue(aircraftType.Models.Contains(model)); Assert.AreEqual(worksheet.String("Type"), aircraftType.Type); Assert.AreEqual(worksheet.ParseEnum<WakeTurbulenceCategory>("Wake"), aircraftType.WakeTurbulenceCategory); Assert.AreEqual(worksheet.ParseEnum<EngineType>("EngineType"), aircraftType.EngineType); Assert.AreEqual(worksheet.String("Engines"), aircraftType.Engines); Assert.AreEqual(worksheet.ParseEnum<Species>("Species"), aircraftType.Species); } }
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 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 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 ServerConfigJson_ToModel_Fills_Model_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); var isLocalAddress = true; using (var cultureSwitcher = new CultureSwitcher(worksheet.String("Culture"))) { var configProperty = worksheet.String("ConfigProperty"); var isMono = worksheet.Bool("IsMono"); _RuntimeEnvironment.Setup(r => r.IsMono).Returns(isMono); switch (configProperty) { case "VrsVersion": _ApplicationInformation.Setup(r => r.ShortVersion).Returns(worksheet.String("Value")); break; case "IsLocalAddress": isLocalAddress = worksheet.Bool("Value"); break; case "IsMono": break; case "InitialMapLatitude": _Configuration.GoogleMapSettings.InitialMapLatitude = worksheet.Double("Value"); break; case "InitialMapLongitude": _Configuration.GoogleMapSettings.InitialMapLongitude = worksheet.Double("Value"); break; case "InitialMapType": _Configuration.GoogleMapSettings.InitialMapType = worksheet.EString("Value"); break; case "InitialMapZoom": _Configuration.GoogleMapSettings.InitialMapZoom = worksheet.Int("Value"); break; case "InitialRefreshSeconds": _Configuration.GoogleMapSettings.InitialRefreshSeconds = worksheet.Int("Value"); break; case "InitialSettings": _Configuration.GoogleMapSettings.InitialSettings = worksheet.EString("Value"); break; case "MinimumRefreshSeconds": _Configuration.GoogleMapSettings.MinimumRefreshSeconds = worksheet.Int("Value"); break; case "InitialDistanceUnit": _Configuration.GoogleMapSettings.InitialDistanceUnit = worksheet.ParseEnum <DistanceUnit>("Value"); break; case "InitialHeightUnit": _Configuration.GoogleMapSettings.InitialHeightUnit = worksheet.ParseEnum <HeightUnit>("Value"); break; case "InitialSpeedUnit": _Configuration.GoogleMapSettings.InitialSpeedUnit = worksheet.ParseEnum <SpeedUnit>("Value"); break; case "CanRunReports": _Configuration.InternetClientSettings.CanRunReports = worksheet.Bool("Value"); break; case "CanShowPinText": _Configuration.InternetClientSettings.CanShowPinText = worksheet.Bool("Value"); break; case "TimeoutMinutes": _Configuration.InternetClientSettings.TimeoutMinutes = worksheet.Int("Value"); break; case "CanPlayAudio": _Configuration.InternetClientSettings.CanPlayAudio = worksheet.Bool("Value"); break; case "CanSubmitRoutes": _Configuration.InternetClientSettings.CanSubmitRoutes = worksheet.Bool("Value"); break; case "CanShowPictures": _Configuration.InternetClientSettings.CanShowPictures = worksheet.Bool("Value"); break; case "AudioEnabled": _Configuration.AudioSettings.Enabled = worksheet.Bool("Value"); break; case "CanShowPolarPlots": _Configuration.InternetClientSettings.CanShowPolarPlots = worksheet.Bool("Value"); break; case "UseMarkerLabels": _Configuration.MonoSettings.UseMarkerLabels = worksheet.Bool("Value"); break; case "UseSvgGraphicsOnDesktop": _Configuration.GoogleMapSettings.UseSvgGraphicsOnDesktop = worksheet.Bool("Value"); break; case "UseSvgGraphicsOnMobile": _Configuration.GoogleMapSettings.UseSvgGraphicsOnMobile = worksheet.Bool("Value"); break; case "UseSvgGraphicsOnReports": _Configuration.GoogleMapSettings.UseSvgGraphicsOnReports = worksheet.Bool("Value"); break; case "OpenStreetMapTileServerUrl": _Configuration.GoogleMapSettings.OpenStreetMapTileServerUrl = worksheet.EString("Value"); break; default: throw new NotImplementedException(); } } var model = ServerConfigJson.ToModel(isLocalAddress); var propertyName = worksheet.String("ConfigProperty"); switch (propertyName) { case "VrsVersion": Assert.AreEqual(worksheet.EString("JsonValue"), model.VrsVersion); break; case "IsLocalAddress": Assert.AreEqual(worksheet.Bool("JsonValue"), model.IsLocalAddress); break; case "IsMono": Assert.AreEqual(worksheet.Bool("JsonValue"), model.IsMono); break; case "InitialMapLatitude": Assert.AreEqual(worksheet.Double("JsonValue"), model.InitialLatitude); break; case "InitialMapLongitude": Assert.AreEqual(worksheet.Double("JsonValue"), model.InitialLongitude); break; case "InitialMapType": Assert.AreEqual(worksheet.EString("JsonValue"), model.InitialMapType); break; case "InitialMapZoom": Assert.AreEqual(worksheet.Int("JsonValue"), model.InitialZoom); break; case "InitialRefreshSeconds": Assert.AreEqual(worksheet.Int("JsonValue"), model.RefreshSeconds); break; case "InitialSettings": Assert.AreEqual(worksheet.EString("JsonValue"), model.InitialSettings); break; case "MinimumRefreshSeconds": Assert.AreEqual(worksheet.Int("JsonValue"), model.MinimumRefreshSeconds); break; case "InitialDistanceUnit": Assert.AreEqual(worksheet.String("JsonValue"), model.InitialDistanceUnit); break; case "InitialHeightUnit": Assert.AreEqual(worksheet.String("JsonValue"), model.InitialHeightUnit); break; case "InitialSpeedUnit": Assert.AreEqual(worksheet.String("JsonValue"), model.InitialSpeedUnit); break; case "CanRunReports": Assert.AreEqual(worksheet.Bool("JsonValue"), model.InternetClientCanRunReports); break; case "CanShowPinText": Assert.AreEqual(worksheet.Bool("JsonValue"), model.InternetClientCanShowPinText); break; case "TimeoutMinutes": Assert.AreEqual(worksheet.Int("JsonValue"), model.InternetClientTimeoutMinutes); break; case "CanPlayAudio": Assert.AreEqual(worksheet.Bool("JsonValue"), model.InternetClientsCanPlayAudio); break; case "CanSubmitRoutes": Assert.AreEqual(worksheet.Bool("JsonValue"), model.InternetClientsCanSubmitRoutes); break; case "CanShowPictures": Assert.AreEqual(worksheet.Bool("JsonValue"), model.InternetClientsCanSeeAircraftPictures); break; case "AudioEnabled": Assert.AreEqual(worksheet.Bool("JsonValue"), model.IsAudioEnabled); break; case "CanShowPolarPlots": Assert.AreEqual(worksheet.Bool("JsonValue"), model.InternetClientsCanSeePolarPlots); break; case "UseMarkerLabels": Assert.AreEqual(worksheet.Bool("JsonValue"), model.UseMarkerLabels); break; case "UseSvgGraphicsOnDesktop": Assert.AreEqual(worksheet.Bool("JsonValue"), model.UseSvgGraphicsOnDesktop); break; case "UseSvgGraphicsOnMobile": Assert.AreEqual(worksheet.Bool("JsonValue"), model.UseSvgGraphicsOnMobile); break; case "UseSvgGraphicsOnReports": Assert.AreEqual(worksheet.Bool("JsonValue"), model.UseSvgGraphicsOnReports); break; case "OpenStreetMapTileServerUrl": Assert.AreEqual(worksheet.EString("JsonValue"), model.OpenStreetMapTileServerUrl); break; default: throw new NotImplementedException(); } }
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); } }