public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> wholeDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            Dictionary<string, object> aggDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(wholeDict.First().Value.ToString());
            Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(aggDict.GetString(AggregationTypeEnum.GeoDistance.ToString()));

            List<DistanceRangeBucket> ranges = new List<DistanceRangeBucket>();
            List<Dictionary<string, object>> bucketDictList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(fieldDict.GetString(_RANGES));
            foreach (Dictionary<string, object> bucketDict in bucketDictList)
            {
                ranges.Add(DeserializeRangeBucket(bucketDict));
            }

            GeoDistanceAggregate agg = new GeoDistanceAggregate(
                wholeDict.First().Key,
                fieldDict.GetString(_FIELD),
                CoordinatePointSerializer.DeserializeCoordinatePoint(fieldDict.GetString(_ORIGIN)),
                ranges);

            agg.Unit = DistanceUnitEnum.Find(fieldDict.GetString(_UNIT, _UNIT_DEFAULT.ToString()));
            agg.DistanceComputeType = DistanceComputeTypeEnum.Find(fieldDict.GetString(_DISTANCE_TYPE, _DISTANCE_TYPE_DEFAULT.ToString()));

            agg.SubAggregations = BucketAggregationBase.DeserializeSubAggregations(aggDict);
            return agg;
        }
        public void PASS_Serialize()
        {
            GeoDistanceAggregate agg = new GeoDistanceAggregate("name", "field",
                new CoordinatePoint(1.1, 2.2),
                new List<DistanceRangeBucket>()
                {
                    new DistanceRangeBucket()
                    {
                        To = 50
                    }
                });

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

            string expectedJson = "{\"name\":{\"geo_distance\":{\"field\":\"field\",\"origin\":{\"lat\":1.1,\"lon\":2.2},\"ranges\":[{\"to\":50.0}]}}}";
            Assert.AreEqual(expectedJson, json);
        }
        public void PASS_Create()
        {
            GeoDistanceAggregate agg = new GeoDistanceAggregate("name", "field",
                new CoordinatePoint(1.1, 2.2),
                new List<DistanceRangeBucket>()
                {
                    new DistanceRangeBucket()
                    {
                        To = 50
                    }
                });

            Assert.IsNotNull(agg);
            Assert.AreEqual("name", agg.Name);
            Assert.AreEqual("field", agg.Field);
            Assert.AreEqual(1.1, agg.OriginPoint.Latitude);
            Assert.AreEqual(2.2, agg.OriginPoint.Longitude);
            Assert.AreEqual((int)50, Convert.ToInt32(agg.Ranges.First().To));
        }