public void PASS_Serialize()
        {
            GeoDistanceFilter filter = new GeoDistanceFilter("field", new DistanceValue("1m"), new CoordinatePoint(1.1, 2.2));
            string json = JsonConvert.SerializeObject(filter);
            Assert.IsNotNull(json);

            string expectedJson = "{\"geo_distance\":{\"distance\":\"1m\",\"field\":{\"lat\":1.1,\"lon\":2.2}}}";
            Assert.AreEqual(expectedJson, json);
        }
 public void PASS_CreateFilter()
 {
     GeoDistanceFilter filter = new GeoDistanceFilter("field", new DistanceValue("1m"), new CoordinatePoint(1.1, 2.2));
     Assert.IsNotNull(filter);
     Assert.AreEqual("field", filter.Field);
     Assert.AreEqual((double)1, filter.Distance.Size);
     Assert.AreEqual(DistanceUnitEnum.Meter, filter.Distance.Unit);
     Assert.AreEqual(1.1, filter.CenterPoint.Latitude);
     Assert.AreEqual(2.2, filter.CenterPoint.Longitude);
 }
 public void FAIL_CreateFilter_Point()
 {
     try
     {
         GeoDistanceFilter filter = new GeoDistanceFilter("field", new DistanceValue("1m"), null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("centerPoint", ex.ParamName);
     }
 }
 public void FAIL_CreateFilter_Distance()
 {
     try
     {
         GeoDistanceFilter filter = new GeoDistanceFilter("field", null, new CoordinatePoint(1.1, 2.2));
         Assert.Fail();
     }
     catch(ArgumentNullException ex)
     {
         Assert.AreEqual("distance", ex.ParamName);
     }
 }
Пример #5
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (fieldDict.ContainsKey(FilterTypeEnum.GeoDistance.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            DistanceValue distance = new DistanceValue(fieldDict.GetString(_DISTANCE));
            KeyValuePair<string, object> fieldKvp = fieldDict.First(x => !_KnownFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase));

            if (string.IsNullOrWhiteSpace(fieldKvp.Key))
                throw new RequiredPropertyMissingException("GeoPointProperty");

            CoordinatePoint point = CoordinatePointSerializer.DeserializeCoordinatePoint(fieldKvp.Value.ToString());

            GeoDistanceFilter filter = new GeoDistanceFilter(fieldKvp.Key, distance, point);

            filter.DistanceComputeMethod = DistanceComputeTypeEnum.Find(fieldDict.GetString(_DISTANCE_TYPE, _DISTANCE_TYPE_DEFAULT.ToString()));
            filter.OptimizeBoundingBox = BoundingBoxOptimizeEnum.Find(fieldDict.GetString(_OPTIMIZE_BBOX, _OPTIMIZE_BBOX_DEFAULT.ToString()));

            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            return filter;
        }