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.GeoDistanceRange.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            if(fieldDict.Count(x => _GreaterFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase)) > 1)
                throw new ConflictingPropertiesException(_GreaterFields);
            if(fieldDict.Count(x => _LesserFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase)) > 1)
                throw new ConflictingPropertiesException(_LesserFields);

            KeyValuePair<string, object> fieldKvp = fieldDict.FirstOrDefault(x => !_KnownFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase));

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

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

            GeoDistanceRangeFilter filter = new GeoDistanceRangeFilter(fieldKvp.Key, point);
            if (fieldDict.ContainsKey(_GREATER_THAN))
            {
                filter.GreaterThan = new DistanceValue(fieldDict.GetString(_GREATER_THAN));
            }
            
            if (fieldDict.ContainsKey(_GREATER_THAN_OR_EQUAL_TO))
            {
                filter.GreaterThanOrEqualTo = new DistanceValue(fieldDict.GetString(_GREATER_THAN_OR_EQUAL_TO));
            }

            if (fieldDict.ContainsKey(_FROM))
            {
                if (fieldDict.ContainsKey(_INCLUDE_LOWER) && fieldDict.GetBool(_INCLUDE_LOWER))
                    filter.GreaterThanOrEqualTo = new DistanceValue(fieldDict.GetString(_FROM));
                else
                    filter.GreaterThan = new DistanceValue(fieldDict.GetString(_FROM));
            }

            if (fieldDict.ContainsKey(_LESS_THAN))
            {
                filter.LessThan = new DistanceValue(fieldDict.GetString(_LESS_THAN));
            }

            if (fieldDict.ContainsKey(_LESS_THAN_OR_EQUAL_TO))
            {
                filter.LessThanOrEqualTo = new DistanceValue(fieldDict.GetString(_LESS_THAN_OR_EQUAL_TO));
            }

            if (fieldDict.ContainsKey(_TO))
            {
                if (fieldDict.ContainsKey(_INCLUDE_UPPER) && fieldDict.GetBool(_INCLUDE_UPPER))
                    filter.LessThanOrEqualTo = new DistanceValue(fieldDict.GetString(_TO));
                else
                    filter.LessThan = new DistanceValue(fieldDict.GetString(_TO));
            }

            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            return filter;
        }
        public void PASS_Serialize()
        {
            GeoDistanceRangeFilter filter = new GeoDistanceRangeFilter("field", new CoordinatePoint(1.1, 2.2))
            {
                GreaterThan = new DistanceValue("1m"),
                LessThan = new DistanceValue("1000m")
            };

            string json = JsonConvert.SerializeObject(filter);
            Assert.IsNotNull(json);

            string expectedJson = "{\"geo_distance_range\":{\"gt\":\"1m\",\"lt\":\"1000m\",\"field\":{\"lat\":1.1,\"lon\":2.2}}}";
            Assert.AreEqual(expectedJson, json);
        }
 public void FAIL_CreateFilter_CenterPoint()
 {
     try
     {
         GeoDistanceRangeFilter filter = new GeoDistanceRangeFilter("field", null)
         {
             GreaterThan = new DistanceValue("1m"),
             LessThan = new DistanceValue("1000m")
         };
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("centerPoint", ex.ParamName);
     }
 }
        public void FAIL_CreateFilter_Field()
        {
            try
            {
                GeoDistanceRangeFilter filter = new GeoDistanceRangeFilter(null, new CoordinatePoint(1.1, 2.2))
                {
                    GreaterThan = new DistanceValue("1m"),
                    LessThan = new DistanceValue("1000m")
                };

                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("field", ex.ParamName);
            }
        }
        public void PASS_CreateFilter()
        {
            GeoDistanceRangeFilter filter = new GeoDistanceRangeFilter("field", new CoordinatePoint(1.1, 2.2))
            {
                GreaterThan = new DistanceValue("1m"),
                LessThan = new DistanceValue("1000m")
            };

            Assert.IsNotNull(filter);
            Assert.AreEqual("field", filter.Field);
            Assert.AreEqual(1.1, filter.CenterPoint.Latitude);
            Assert.AreEqual(2.2, filter.CenterPoint.Longitude);
            Assert.AreEqual((double)1, filter.GreaterThan.Size);
            Assert.AreEqual(DistanceUnitEnum.Meter, filter.GreaterThan.Unit);
            Assert.AreEqual((double)1000, filter.LessThan.Size);
            Assert.AreEqual(DistanceUnitEnum.Meter, filter.LessThan.Unit);
        }