public void PASS_Create()
 {
     FilterAggregate agg = new FilterAggregate("filter-name", new TermFilter("field", "value"));
     Assert.IsNotNull(agg);
     Assert.AreEqual("filter-name", agg.Name);
     Assert.AreEqual("field", (agg.Filter as TermFilter).Field);
     Assert.AreEqual("value", (agg.Filter as TermFilter).Value);
 }
        public void PASS_Serialize()
        {
            FilterAggregate agg = new FilterAggregate("filter-name", new TermFilter("field", "value"));
            string json = JsonConvert.SerializeObject(agg);
            Assert.IsNotNull(json);

            string expectedJson = "{\"filter-name\":{\"filter\":{\"term\":{\"field\":\"value\"}}}}";
            Assert.AreEqual(expectedJson, json);
        }
Exemplo n.º 3
0
        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());

            FilterAggregate agg = new FilterAggregate(
                wholeDict.First().Key, 
                JsonConvert.DeserializeObject<IFilter>(aggDict.GetString(AggregationTypeEnum.Filter.ToString())));

            agg.SubAggregations = BucketAggregationBase.DeserializeSubAggregations(aggDict);
            return agg;
        }
        public void PASS_Serialize_Subs()
        {
            FilterAggregate agg = new FilterAggregate("filter-name", new TermFilter("field", "value"))
            {
                SubAggregations = new List<IAggregation>() 
                { 
                    new SumAggregate("sum-name", "field")
                }
            };
            string json = JsonConvert.SerializeObject(agg);
            Assert.IsNotNull(json);

            string expectedJson = "{\"filter-name\":{\"filter\":{\"term\":{\"field\":\"value\"}},\"aggregations\":{\"sum-name\":{\"sum\":{\"field\":\"field\"}}}}}";
            Assert.AreEqual(expectedJson, json);
        }