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 Cidr_Parse_Parses_Addresses_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); // Uncomment this block if you want to restrict the test to just those rows with a RunThis of true // var runThis = worksheet.NBool("RunThis").GetValueOrDefault(); // if(!runThis) Assert.Fail(); var address = worksheet.EString("Parse"); Exception exception = null; Cidr cidr = null; try { cidr = Cidr.Parse(address); } catch (Exception ex) { exception = ex; } Assert.AreEqual(exception != null, worksheet.NBool("Exception").GetValueOrDefault(), exception == null ? "Did not see exception" : exception.Message); if (exception == null) { Assert.AreEqual(GetExcelIPAddress(worksheet, "Address"), cidr.Address); Assert.AreEqual(GetExcelIPAddress(worksheet, "MaskedAddress"), cidr.MaskedAddress); Assert.AreEqual(worksheet.Int("BitmaskBits"), cidr.BitmaskBits); Assert.AreEqual(worksheet.UInt("IPv4Bitmask"), cidr.IPv4Bitmask); Assert.AreEqual(GetExcelIPAddress(worksheet, "From"), cidr.FirstMatchingAddress); Assert.AreEqual(GetExcelIPAddress(worksheet, "To"), cidr.LastMatchingAddress); } }
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 Cidr_TryParse_Parses_Addresses_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); Cidr cidr; var address = worksheet.EString("Parse"); var parsed = Cidr.TryParse(address, out cidr); Assert.AreEqual(!parsed, worksheet.NBool("Exception").GetValueOrDefault()); if (parsed) { Assert.AreEqual(GetExcelIPAddress(worksheet, "Address"), cidr.Address); Assert.AreEqual(GetExcelIPAddress(worksheet, "MaskedAddress"), cidr.MaskedAddress); Assert.AreEqual(worksheet.Int("BitmaskBits"), cidr.BitmaskBits); Assert.AreEqual(worksheet.UInt("IPv4Bitmask"), cidr.IPv4Bitmask); } }
public void JsonSerialiser_WriteObject_Honours_Important_DataMember_Attributes() { var worksheet = new ExcelWorksheetData(TestContext); var obj = new Attributes() { OriginalName = worksheet.Int("OriginalName"), NoEmitDefaultString = worksheet.EString("NoEmitDefaultString"), NoEmitDefaultInt = worksheet.Int("NoEmitDefaultInt"), NoEmitDefaultBool = worksheet.Bool("NoEmitDefaultBool"), NoEmitDefaultLong = worksheet.Long("NoEmitDefaultLong"), NoEmitDefaultDateTime = worksheet.DateTime("NoEmitDefaultDateTime"), NoEmitDefaultNullable = worksheet.NBool("NoEmitDefaultNullable"), }; _JsonSerialiser.Initialise(typeof(Attributes)); _JsonSerialiser.WriteObject(_Stream, obj); Assert.AreEqual(worksheet.EString("Json"), GetJson()); }
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 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 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 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); }