public void PASS_Serialize()
        {
            GeoShapeQuery query = new GeoShapeQuery("field", new Point(new CoordinatePoint(1.1, 2.2)));
            string json = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(json);

            string expectedJson = "{\"geo_shape\":{\"field\":{\"shape\":{\"type\":\"point\",\"coordinates\":[2.2,1.1]}}}}";
            Assert.AreEqual(expectedJson, json);
        }
 public void PASS_CreateQuery()
 {
     GeoShapeQuery query = new GeoShapeQuery("field", new Point(new CoordinatePoint(1.1, 2.2)));
     Assert.IsNotNull(query);
     Assert.AreEqual("field", query.Field);
     Assert.IsTrue(query.GeoShape is Point);
     Assert.AreEqual(1.1, (query.GeoShape as Point).Coordinate.Latitude);
     Assert.AreEqual(2.2, (query.GeoShape as Point).Coordinate.Longitude);
 }
 public void FAIL_CreateQuery_GeoShape()
 {
     try
     {
         GeoShapeQuery query = new GeoShapeQuery("field", null);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("geoShape", argEx.ParamName);
     }
 }
 public void FAIL_CreateQuery_Field()
 {
     try
     {
         GeoShapeQuery query = new GeoShapeQuery(null, new Point(new CoordinatePoint(1.1, 2.2)));
         Assert.Fail();
     }
     catch(ArgumentNullException argEx)
     {
         Assert.AreEqual("field", argEx.ParamName);
     }
 }
예제 #5
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> shapeDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (shapeDict.ContainsKey(_GEO_SHAPE))
                shapeDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(shapeDict.First().Value.ToString());

            string fieldName = shapeDict.First().Key;
            GeoShapeBase shape = JsonConvert.DeserializeObject<GeoShapeBase>(shapeDict.First().Value.ToString());
            
            GeoShapeQuery query = new GeoShapeQuery(fieldName, shape); 
            query.QueryName = shapeDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);
            return query;
        }