public void And_Coordinates_Property_Is_NonNull_Then_Coordinates_Should_Be_In_New_Format() { string testJson = DummyTimeLineJson.GetTimeLineJsonWithCoordinatesPropertySet(); List <TimeLine> timeline = JsonConvert.DeserializeObject <List <TimeLine> >(testJson); AssertCoordinateFormatForTypedCoordinateContainer(timeline.FirstOrDefault().Coordinates); }
public void And_Place_Property_Is_NonNull_Then_Deserialization_Should_Not_Throw_Errors(string coordinateType) { string testJson = DummyTimeLineJson.GetTimeLineJsonWithPlacePropertySet(coordinateType); Assert.DoesNotThrow(() => { List <TimeLine> test = JsonConvert.DeserializeObject <List <TimeLine> >(testJson); }); }
private void AssertCoordinateFormatForTypedCoordinateContainer(TypedCoordinateContainer coordContainer) { //TJM: The result should be dealing with a Point type for simplicity to check the coordinates. ICoordinateCollection coordColl = coordContainer.Coordinates.Coordinates; while (coordColl.Children != null) { coordColl = coordColl.Children.FirstOrDefault(); } CoordinatePair coordPair = coordColl as CoordinatePair; string expectedResult = DummyTimeLineJson.GetCoordinateTestValueFromType("Point", coordPair.IsLegacyFormat); //TJM: Kind of a hack, but whatever...I want to get the exact result from our sample data. expectedResult = expectedResult.Replace("[", "").Replace("]", ""); string[] coordinateSplit = expectedResult.Split(','); // Set values based on whether we're using legacy format for the coordinate. decimal latitude = 0; decimal longitude = 0; for (int i = 0; i < coordinateSplit.Length; i++) { decimal coordNum; if (decimal.TryParse(coordinateSplit[i], out coordNum)) { if (i == 0) { if (coordPair.IsLegacyFormat) { latitude = coordNum; } else { longitude = coordNum; } } else if (i == 1) { if (coordPair.IsLegacyFormat) { longitude = coordNum; } else { latitude = coordNum; } } } } AssertLatitudeandLongitude(latitude, longitude, coordPair); }