public void AirPressureLookup_FindClosest_Returns_Correct_AirPressure_Record() { var worksheet = new ExcelWorksheetData(TestContext); for (var i = 1; i <= 3; ++i) { var latitudeColumn = String.Format("Lat{0}", i); var longitudeColumn = String.Format("Lng{0}", i); if (worksheet.String(latitudeColumn) != null) { _AirPressures.Add(new AirPressure() { Latitude = worksheet.Float(latitudeColumn), Longitude = worksheet.Float(longitudeColumn), AgeSeconds = (short)i, }); } } _Lookup.LoadAirPressures(_AirPressures, _Now); var expected = worksheet.Int("Closest"); var actual = _Lookup.FindClosest(worksheet.Float("Lat"), worksheet.Float("Lng")); Assert.AreEqual(expected, actual.AgeSeconds); }
public void Aircraft_UpdateCoordinates_Resets_Coordinates_If_Aircraft_Looks_To_Be_Moving_Impossibly_Quickly() { // Some aircraft's transponders report the wrong position. Further, some radios misinterpret position updates at // extreme ranges. We can guess the position is wrong if the position and timing of two updates would require the // aircraft to be moving at incredibly high speeds. When this is detected we should reset the trails, otherwise the // user sees long lines drawn across the map, or a scribble effect if the transponder is just reporting nonsense. var worksheet = new ExcelWorksheetData(TestContext); var time = DateTime.UtcNow; var shortSeconds = 24 * 60 * 60; // seconds in a day _Aircraft.DataVersion = time.Ticks; _Aircraft.Latitude = worksheet.Float("Lat1"); _Aircraft.Longitude = worksheet.Float("Lng1"); _Aircraft.Track = 1; _Aircraft.UpdateCoordinates(time, shortSeconds); int milliseconds = worksheet.Int("Milliseconds"); time = time.AddMilliseconds(milliseconds); _Aircraft.DataVersion = time.Ticks; _Aircraft.Latitude = worksheet.Float("Lat2"); _Aircraft.Longitude = worksheet.Float("Lng2"); _Aircraft.Track = 2; _Aircraft.UpdateCoordinates(time, shortSeconds); if (!worksheet.Bool("ResetTrail")) { if (milliseconds >= 1000) { Assert.AreEqual(2, _Aircraft.FullCoordinates.Count); Assert.AreEqual(2, _Aircraft.ShortCoordinates.Count); } else { Assert.AreEqual(1, _Aircraft.FullCoordinates.Count); Assert.AreEqual(1, _Aircraft.ShortCoordinates.Count); Assert.AreEqual(1, _Aircraft.FullCoordinates[0].Heading); Assert.AreEqual(1, _Aircraft.ShortCoordinates[0].Heading); } } else { if (milliseconds < 1000) { Assert.AreEqual(0, _Aircraft.FullCoordinates.Count); Assert.AreEqual(0, _Aircraft.ShortCoordinates.Count); } else { Assert.AreEqual(1, _Aircraft.FullCoordinates.Count); Assert.AreEqual(1, _Aircraft.ShortCoordinates.Count); Assert.AreEqual(2, _Aircraft.FullCoordinates[0].Heading); Assert.AreEqual(2, _Aircraft.ShortCoordinates[0].Heading); } } }
public void Aircraft_UpdateCoordinates_Replaces_Last_Full_Coordinate_If_Track_Hardly_Changes() { // If an update changes the position but the aircraft remains on the same ground track as the previous position // then there's no need to keep the previous position, it can be replaced with the current one. var worksheet = new ExcelWorksheetData(TestContext); var time = DateTime.Now; var expected = new List <Coordinate>(); for (int i = 1; i <= 4; ++i) { var latInColumn = String.Format("Lat{0}", i); var lngInColumn = String.Format("Lng{0}", i); var trkInColumn = String.Format("Trk{0}", i); var latOutColumn = String.Format("CLat{0}", i); var lngOutColumn = String.Format("CLng{0}", i); var trkOutColumn = String.Format("CTrk{0}", i); if (worksheet.String(latInColumn) != null) { time = time.AddHours(1); _Aircraft.DataVersion = time.Ticks; _Aircraft.Latitude = worksheet.Float(latInColumn); _Aircraft.Longitude = worksheet.Float(lngInColumn); _Aircraft.Track = worksheet.NFloat(trkInColumn); _Aircraft.UpdateCoordinates(time, 300 * 60 * 60); Assert.AreEqual(i, _Aircraft.ShortCoordinates.Count); } if (worksheet.String(latOutColumn) != null) { expected.Add(new Coordinate(0, 0, worksheet.Float(latOutColumn), worksheet.Float(lngOutColumn), worksheet.NFloat(trkOutColumn))); } } Assert.AreEqual(expected.Count, _Aircraft.FullCoordinates.Count); for (int i = 0; i < expected.Count; ++i) { var expCoordinate = expected[i]; var fullCoordinate = _Aircraft.FullCoordinates[i]; Assert.AreEqual(expCoordinate, fullCoordinate, i.ToString()); Assert.AreEqual(expCoordinate.Heading, fullCoordinate.Heading, i.ToString()); } }
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 Aircraft_UpdateCoordinates_Resets_Coordinates_If_Aircraft_Looks_To_Be_Moving_Impossibly_Quickly() { // Some aircraft's transponders report the wrong position. Further, some radios misinterpret position updates at // extreme ranges. We can guess the position is wrong if the position and timing of two updates would require the // aircraft to be moving at incredibly high speeds. When this is detected we should reset the trails, otherwise the // user sees long lines drawn across the map, or a scribble effect if the transponder is just reporting nonsense. var worksheet = new ExcelWorksheetData(TestContext); var time = DateTime.UtcNow; var shortSeconds = 24 * 60 * 60; // seconds in a day _Aircraft.DataVersion = time.Ticks; _Aircraft.Latitude = worksheet.Float("Lat1"); _Aircraft.Longitude = worksheet.Float("Lng1"); _Aircraft.Track = 1; _Aircraft.UpdateCoordinates(time, shortSeconds); int milliseconds = worksheet.Int("Milliseconds"); time = time.AddMilliseconds(milliseconds); _Aircraft.DataVersion = time.Ticks; _Aircraft.Latitude = worksheet.Float("Lat2"); _Aircraft.Longitude = worksheet.Float("Lng2"); _Aircraft.Track = 2; _Aircraft.UpdateCoordinates(time, shortSeconds); if(!worksheet.Bool("ResetTrail")) { if(milliseconds >= 1000) { Assert.AreEqual(2, _Aircraft.FullCoordinates.Count); Assert.AreEqual(2, _Aircraft.ShortCoordinates.Count); } else { Assert.AreEqual(1, _Aircraft.FullCoordinates.Count); Assert.AreEqual(1, _Aircraft.ShortCoordinates.Count); Assert.AreEqual(1, _Aircraft.FullCoordinates[0].Heading); Assert.AreEqual(1, _Aircraft.ShortCoordinates[0].Heading); } } else { if(milliseconds < 1000) { Assert.AreEqual(0, _Aircraft.FullCoordinates.Count); Assert.AreEqual(0, _Aircraft.ShortCoordinates.Count); } else { Assert.AreEqual(1, _Aircraft.FullCoordinates.Count); Assert.AreEqual(1, _Aircraft.ShortCoordinates.Count); Assert.AreEqual(2, _Aircraft.FullCoordinates[0].Heading); Assert.AreEqual(2, _Aircraft.ShortCoordinates[0].Heading); } } }
public void Aircraft_UpdateCoordinates_Replaces_Last_Full_Coordinate_If_Track_Hardly_Changes() { // If an update changes the position but the aircraft remains on the same ground track as the previous position // then there's no need to keep the previous position, it can be replaced with the current one. var worksheet = new ExcelWorksheetData(TestContext); var time = DateTime.Now; var expected = new List<Coordinate>(); for(int i = 1;i <= 4;++i) { var latInColumn = String.Format("Lat{0}", i); var lngInColumn = String.Format("Lng{0}", i); var trkInColumn = String.Format("Trk{0}", i); var latOutColumn = String.Format("CLat{0}", i); var lngOutColumn = String.Format("CLng{0}", i); var trkOutColumn = String.Format("CTrk{0}", i); if(worksheet.String(latInColumn) != null) { time = time.AddHours(1); _Aircraft.DataVersion = time.Ticks; _Aircraft.Latitude = worksheet.Float(latInColumn); _Aircraft.Longitude = worksheet.Float(lngInColumn); _Aircraft.Track = worksheet.NFloat(trkInColumn); _Aircraft.UpdateCoordinates(time, 300 * 60 * 60); Assert.AreEqual(i, _Aircraft.ShortCoordinates.Count); } if(worksheet.String(latOutColumn) != null) { expected.Add(new Coordinate(0, 0, worksheet.Float(latOutColumn), worksheet.Float(lngOutColumn), worksheet.NFloat(trkOutColumn))); } } Assert.AreEqual(expected.Count, _Aircraft.FullCoordinates.Count); for(int i = 0;i < expected.Count;++i) { var expCoordinate = expected[i]; var fullCoordinate = _Aircraft.FullCoordinates[i]; Assert.AreEqual(expCoordinate, fullCoordinate, i.ToString()); Assert.AreEqual(expCoordinate.Heading, fullCoordinate.Heading, i.ToString()); } }
/// <summary> /// Returns a mock flight record with values filled from a spreadsheet row, starting from the column number passed across. /// </summary> /// <param name="expected"></param> /// <param name="firstOrdinal"></param> /// <returns></returns> /// <remarks> /// The columns are read in the following order: /// AircraftID, Callsign, EndTime, FirstAltitude, FirstGroundSpeed, FirstIsOnGround, FirstLat, FirstLon, FirstSquawk, FirstTrack, FirstVerticalRate, HadAlert, /// HadEmergency, HadSpi, LastAltitude, LastGroundSpeed, LastIsOnGround, LastLat, LastLon, LastSquawk, LastTrack, LastVerticalRate, NumADSBMsgRec, NumModeSMsgRec, /// NumIDMsgRec, NumSurPosMsgRec, NumAirPosMsgRec, NumAirVelMsgRec, NumSurAltMsgRec, NumSurIDMsgRec, NumAirToAirMsgRec, NumAirCallRepMsgRec, NumPosMsgRec /// and StartTime /// </remarks> private BaseStationFlight LoadFlightFromSpreadsheet(ExcelWorksheetData worksheet, int firstOrdinal = 0, BaseStationFlight copyIntoFlight = null) { int ordinal = firstOrdinal; var aircraft = CreateAircraft(); aircraft.AircraftID = worksheet.Int(ordinal++); var result = copyIntoFlight == null ? CreateFlight(aircraft) : copyIntoFlight; result.AircraftID = aircraft.AircraftID; result.Callsign = worksheet.EString(ordinal++); result.EndTime = worksheet.DateTime(ordinal++); result.FirstAltitude = worksheet.Int(ordinal++); result.FirstGroundSpeed = worksheet.Float(ordinal++); result.FirstIsOnGround = worksheet.Bool(ordinal++); result.FirstLat = worksheet.Float(ordinal++); result.FirstLon = worksheet.Float(ordinal++); result.FirstSquawk = worksheet.Int(ordinal++); result.FirstTrack = worksheet.Float(ordinal++); result.FirstVerticalRate = worksheet.Int(ordinal++); result.HadAlert = worksheet.Bool(ordinal++); result.HadEmergency = worksheet.Bool(ordinal++); result.HadSpi = worksheet.Bool(ordinal++); result.LastAltitude = worksheet.Int(ordinal++); result.LastGroundSpeed = worksheet.Float(ordinal++); result.LastIsOnGround = worksheet.Bool(ordinal++); result.LastLat = worksheet.Float(ordinal++); result.LastLon = worksheet.Float(ordinal++); result.LastSquawk = worksheet.Int(ordinal++); result.LastTrack = worksheet.Float(ordinal++); result.LastVerticalRate = worksheet.Int(ordinal++); result.NumADSBMsgRec = worksheet.Int(ordinal++); result.NumModeSMsgRec = worksheet.Int(ordinal++); result.NumIDMsgRec = worksheet.Int(ordinal++); result.NumSurPosMsgRec = worksheet.Int(ordinal++); result.NumAirPosMsgRec = worksheet.Int(ordinal++); result.NumAirVelMsgRec = worksheet.Int(ordinal++); result.NumSurAltMsgRec = worksheet.Int(ordinal++); result.NumSurIDMsgRec = worksheet.Int(ordinal++); result.NumAirToAirMsgRec = worksheet.Int(ordinal++); result.NumAirCallRepMsgRec = worksheet.Int(ordinal++); result.NumPosMsgRec = worksheet.Int(ordinal++); result.StartTime = worksheet.DateTime(ordinal++); return result; }
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 WebSite_BaseStationAircraftList_AircraftListFilter_PositionWithin_Works_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); _AircraftListAddress.Filter = _AircraftListFilter; AddBlankAircraft(1); _BaseStationAircraft[0].Latitude = worksheet.NFloat("Latitude"); _BaseStationAircraft[0].Longitude = worksheet.NFloat("Longitude"); _AircraftListFilter.PositionWithin = new Pair<Coordinate>( new Coordinate(worksheet.Float("Top"), worksheet.Float("Left")), new Coordinate(worksheet.Float("Bottom"), worksheet.Float("Right")) ); var list = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address); Assert.AreEqual(worksheet.Bool("IsInBounds") ? 1 : 0, list.Aircraft.Count); }
public void WebSite_BaseStationAircraftList_AircraftListFilter_Distance_AircraftListFiltered_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); _AircraftListAddress.Filter = _AircraftListFilter; _AircraftListAddress.BrowserLatitude = worksheet.Float("BrowserLatitude"); _AircraftListAddress.BrowserLongitude = worksheet.Float("BrowserLongitude"); AddBlankAircraft(1); _BaseStationAircraft[0].Latitude = worksheet.NFloat("AircraftLatitude"); _BaseStationAircraft[0].Longitude = worksheet.NFloat("AircraftLongitude"); _AircraftListFilter.DistanceLower = worksheet.NDouble("DistanceLower"); _AircraftListFilter.DistanceUpper = worksheet.NDouble("DistanceUpper"); bool passed = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address).Aircraft.Count == 1; Assert.AreEqual(worksheet.Bool("Passes"), passed); }
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); } } }