public void And_Geo_Object_Is_Being_Deserialized_Then_TypedCoordinateContainer_Object_Is_Correctly_Created(string inputJson, string coordinateType) { TypedCoordinateContainer result = JsonConvert.DeserializeObject <TypedCoordinateContainer>(inputJson, new JsonConverter[] { new TypedCoordinateContainerJsonConverter(true) }); switch (coordinateType) { case "Unknown": AssertsForUnknown(result); return; case "Point": AssertsForPoint(result); return; case "LineString": AssertsForLineString(result); return; case "Polygon": AssertsForPolygon(result); return; case "GeometryCollection": AssertsForGeometryCollection(result); return; default: Assert.Fail(); break; } }
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); }
protected void AssertsForGeometryCollection(TypedCoordinateContainer result) { Assert.IsNull(result); }
protected void AssertsForPolygon(TypedCoordinateContainer result) { Assert.IsNotNull(result); Assert.IsNotNull(result.Coordinates); Assert.IsTrue(result.Coordinates.GetType().Name == "PolygonCoordinate"); }
protected void AssertsForLineString(TypedCoordinateContainer result) { Assert.IsNotNull(result); Assert.IsNotNull(result.Coordinates); Assert.IsTrue(result.Coordinates.GetType().Name == "LineStringCoordinate"); }
protected void AssertsForUnknown(TypedCoordinateContainer result) { Assert.IsNull(result); }