public void PASS_Serialize()
        {
            IPv4RangeAggregate agg = new IPv4RangeAggregate("name", "field",
                new List<IpRangeBucket>()
                {
                    new IpRangeBucket()
                    {
                        To = "to",
                        From = "from"
                    }
                });

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

            string expectedJson = "{\"name\":{\"ip_range\":{\"field\":\"field\",\"ranges\":[{\"to\":\"to\",\"from\":\"from\"}]}}}";
            Assert.AreEqual(expectedJson, json);
        }
        public void PASS_Create()
        {
            IPv4RangeAggregate agg = new IPv4RangeAggregate("name", "field",
                new List<IpRangeBucket>()
                {
                    new IpRangeBucket()
                    {
                        To = "to",
                        From = "from"
                    }
                });

            Assert.IsNotNull(agg);
            Assert.AreEqual("name", agg.Name);
            Assert.AreEqual("field", agg.Field);
            Assert.AreEqual("to", agg.Ranges.First().To.ToString());
            Assert.AreEqual("from", agg.Ranges.First().From.ToString());
        }
        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.IpRange.ToString()));

            string aggName = wholeDict.First().Key;
            string field = fieldDict.GetString(_FIELD);

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

            IPv4RangeAggregate agg = new IPv4RangeAggregate(aggName, field, buckets);
            agg.SubAggregations = BucketAggregationBase.DeserializeSubAggregations(aggDict);
            return agg;
        }