public void Geometry_Can_Serialize() { var geo = new Geometry(); var stringBuilder = new StringBuilder(); var writer = XmlWriter.Create(stringBuilder); var xmlSerializer = new XmlSerializer(typeof(Geometry)); xmlSerializer.Serialize(writer, geo); }
public void Geometry_Ctor_Parses_JsonData() { var geometryJson = JsonMapper.ToObject(GeometryJson); var geometry = new Geometry(geometryJson); Assert.Equal("Polygon", geometry.Type); Assert.NotNull(geometry.Coordinates); Assert.Equal(4, geometry.Coordinates.Count); Coordinate coord = geometry.Coordinates.First(); Assert.Equal(-122.51368188, coord.Longitude); Assert.Equal(37.70813196, coord.Latitude); }
internal Place(JsonData place) { if (place == null) return; ID = place.GetValue<string>("id"); Name = place.GetValue<string>("name"); Country = place.GetValue<string>("country"); CountryCode = place.GetValue<string>("country_code"); FullName = place.GetValue<string>("full_name"); PlaceType = place.GetValue<string>("place_type"); Url = place.GetValue<string>("url"); BoundingBox = new Geometry(place.GetValue<JsonData>("bounding_box")); Geometry = new Geometry(place.GetValue<JsonData>("geometry")); var containedWithin = place.GetValue<JsonData>("contained_within"); ContainedWithin = containedWithin != null && containedWithin.Count > 0 ? new Place(containedWithin[0]) : null; var polyLines = place.GetValue<JsonData>("polylines"); PolyLines = polyLines == null ? new List<string>() : (from JsonData line in polyLines select line.ToString()) .ToList(); var attrDict = place.GetValue<JsonData>("attributes") as IDictionary<string, JsonData>; Attributes = attrDict == null ? new Dictionary<string, string>() : (from string key in attrDict.Keys select new { Key = key, Val = attrDict[key].ToString() }) .ToDictionary( attr => attr.Key, attr => attr.Val); }
public void Geometry_Ctor_Returns_On_Null_JsonData() { var geometry = new Geometry(null); Assert.Equal(null, geometry.Type); }
/// <summary> /// Converts XML to Place /// </summary> /// <param name="place">XML containing place info</param> /// <returns>Place populated from XML</returns> public static Place CreatePlace(XElement place) { if (place == null || place.Descendants().Count() == 0) { return null; } var geometry = new Geometry(); return new Place { ID = place.Element("id").Value, Name = place.Element("name").Value, Country = place.Element("country") == null ? string.Empty : place.Element("country").Value, CountryCode = place.Element("country_code") == null ? place.Element("country") != null && place.Element("country").Attribute("code") != null ? place.Element("country").Attribute("code").Value : string.Empty : place.Element("country_code").Value, FullName = place.Element("full_name").Value, PlaceType = place.Element("place_type").Value, Url = place.Element("url").Value, BoundingBox = geometry.CreateGeometry(place.Element("bounding_box")), ContainedWithin = CreatePlace(place.Element("item")), Geometry = geometry.CreateGeometry(place.Element("geometry")), PolyLines = place.Element("polylines") == null ? string.Empty : place.Element("polylines").Element("item").Value }; }