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 Describe_Bytes_Formats_Bytes_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); using(var switcher = new CultureSwitcher(worksheet.String("Region"))) { Assert.AreEqual(worksheet.String("Description"), Describe.Bytes(worksheet.Long("Bytes"))); } }
public void Describe_Bytes_Formats_Bytes_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); using (var switcher = new CultureSwitcher(worksheet.String("Region"))) { Assert.AreEqual(worksheet.String("Description"), Describe.Bytes(worksheet.Long("Bytes"))); } }
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()); }
public void JavascriptHelper_ToJavascriptTicks_Returns_Correct_Value_When_Passed_Date() { var worksheet = new ExcelWorksheetData(TestContext); Assert.AreEqual(worksheet.Long("JavascriptTicks"), JavascriptHelper.ToJavascriptTicks(worksheet.DateTime("Date"))); }
public void RawMessageTranslator_Translate_Extracts_Position_From_ADSB_Messages_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); _Translator.ReceiverLocation = ParseGlobalPosition(worksheet.String("ReceiverPosn")); _Translator.ReceiverRangeKilometres = worksheet.Int("Range"); _Translator.GlobalDecodeAirborneThresholdMilliseconds = worksheet.Int("GATS"); _Translator.GlobalDecodeFastSurfaceThresholdMilliseconds = worksheet.Int("GFSTS"); _Translator.GlobalDecodeSlowSurfaceThresholdMilliseconds = worksheet.Int("GSSTS"); _Translator.LocalDecodeMaxSpeedAirborne = worksheet.Double("LAMS"); _Translator.LocalDecodeMaxSpeedTransition = worksheet.Double("LTMS"); _Translator.LocalDecodeMaxSpeedSurface = worksheet.Double("LSMS"); _Translator.SuppressReceiverRangeCheck = worksheet.Bool("SRRC"); _Translator.UseLocalDecodeForInitialPosition = worksheet.Bool("ULD"); DateTime now = DateTime.UtcNow; for(var i = 1;i <= 4;++i) { var millisecondsColumn = String.Format("MSec{0}", i); var cprColumn = String.Format("CPR{0}", i); var speedColumn = String.Format("Spd{0}", i); var positionColumn = String.Format("Posn{0}", i); if(worksheet.String(cprColumn) == null) continue; var cpr = ParseCpr(worksheet.String(cprColumn)); var speed = worksheet.NDouble(speedColumn); var expectedPosition = ParseGlobalPosition(worksheet.String(positionColumn)); if(i != 1 && worksheet.String(millisecondsColumn) != null) { now = now.AddMilliseconds(worksheet.Int(millisecondsColumn)); } var modeSMessage = new ModeSMessage() { DownlinkFormat = DownlinkFormat.ExtendedSquitter, Icao24 = 0x112233, ParityInterrogatorIdentifier = 0 }; var adsbMessage = new AdsbMessage(modeSMessage); switch(cpr.NumberOfBits) { case 17: adsbMessage.MessageFormat = MessageFormat.AirbornePosition; adsbMessage.AirbornePosition = new AirbornePositionMessage() { CompactPosition = cpr }; break; case 19: adsbMessage.MessageFormat = MessageFormat.SurfacePosition; adsbMessage.SurfacePosition = new SurfacePositionMessage() { CompactPosition = cpr, GroundSpeed = speed, }; break; } var baseStationMessage = _Translator.Translate(now, modeSMessage, adsbMessage); var failMessage = String.Format("Failed on message {0}", i); if(expectedPosition == null) { if(baseStationMessage != null) { if(baseStationMessage.Latitude != null || baseStationMessage.Longitude != null) { Assert.Fail(String.Format("Position decoded to {0}/{1} erroneously. {2}", baseStationMessage.Latitude, baseStationMessage.Longitude, failMessage)); } } } else { Assert.IsNotNull(baseStationMessage.Latitude, failMessage); Assert.IsNotNull(baseStationMessage.Longitude, failMessage); Assert.AreEqual(expectedPosition.Latitude, baseStationMessage.Latitude.Value, 0.0001, failMessage); Assert.AreEqual(expectedPosition.Longitude, baseStationMessage.Longitude.Value, 0.0001, failMessage); } } Assert.AreEqual(worksheet.Int("ResetCount"), _PositionResetEvent.CallCount); Assert.AreEqual(worksheet.Int("ResetCount") > 0 ? 1L : 0L, _Statistics.AdsbPositionsReset); Assert.AreEqual(worksheet.Long("BadRange"), _Statistics.AdsbPositionsOutsideRange); Assert.AreEqual(worksheet.Long("BadSpeed"), _Statistics.AdsbPositionsExceededSpeedCheck); }
public void WebSite_BaseStationAircraftList_Builds_Arrays_Of_Trail_Coordinates_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); AddBlankAircraft(1); var aircraft = _BaseStationAircraft[0]; Mock<IAircraft> mockAircraft = Mock.Get(aircraft); aircraft.Latitude = worksheet.NFloat("ACLat"); aircraft.Longitude = worksheet.NFloat("ACLng"); aircraft.Track = worksheet.NFloat("ACTrk"); aircraft.FirstCoordinateChanged = worksheet.Long("ACFirstCoCh"); aircraft.LastCoordinateChanged = worksheet.Long("ACLastCoCh"); aircraft.PositionTime = new DateTime(1970, 1, 1, 0, 0, 0, worksheet.Int("ACPosTimeCh")); mockAircraft.Setup(m => m.PositionTimeChanged).Returns(worksheet.Long("ACPosTimeCh")); for(int i = 1;i <= 2;++i) { var dataVersion = String.Format("Coord{0}DV", i); var tick = String.Format("Coord{0}Tick", i); var latitude = String.Format("Coord{0}Lat", i); var longitude = String.Format("Coord{0}Lng", i); var track = String.Format("Coord{0}Trk", i); if(worksheet.String(dataVersion) != null) { DateTime dotNetDate = new DateTime(1970, 1, 1, 0, 0, 0, worksheet.Int(tick)); var coordinate = new Coordinate(worksheet.Long(dataVersion), dotNetDate.Ticks, worksheet.Float(latitude), worksheet.Float(longitude), worksheet.NFloat(track)); aircraft.FullCoordinates.Add(coordinate); aircraft.ShortCoordinates.Add(coordinate); } } _AircraftListAddress.PreviousDataVersion = worksheet.Long("ArgsPrevDV"); if(worksheet.Bool("ArgsIsPrevAC")) _AircraftListAddress.PreviousAircraft.Add(0); _AircraftListAddress.ShowShortTrail = worksheet.Bool("ArgsShort"); _AircraftListAddress.ResendTrails = worksheet.Bool("ArgsResend"); var aircraftJson = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address).Aircraft[0]; var count = worksheet.Int("Count"); if(count == 0) { Assert.IsNull(aircraftJson.ShortCoordinates); Assert.IsNull(aircraftJson.FullCoordinates); } else { var list = worksheet.Bool("IsShort") ? aircraftJson.ShortCoordinates : aircraftJson.FullCoordinates; Assert.AreEqual(count, list.Count); for(int i = 0;i < count;++i) { var column = String.Format("R{0}", i); Assert.AreEqual(worksheet.NDouble(column), list[i], "Element {0}", i); } } Assert.AreEqual(worksheet.Bool("ResetTrail"), aircraftJson.ResetTrail); }
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); } } }