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

            List<string> indices = new List<string>();
            if (fieldDict.ContainsKey(_INDEX))
                indices.Add(fieldDict.GetString(_INDEX));
            else if (fieldDict.ContainsKey(_INDICES))
                indices = JsonConvert.DeserializeObject<List<string>>(fieldDict.GetString(_INDICES));
            else
                throw new RequiredPropertyMissingException(_INDEX + "/" + _INDICES);

            IFilter matchingFilter = JsonConvert.DeserializeObject<IFilter>(fieldDict[_FILTER].ToString());

            NonMatchingTypeEnum nonMatching = NonMatchingTypeEnum.None;
            nonMatching = NonMatchingTypeEnum.Find(fieldDict.GetString(_NON_MATCHING_FILTER));

            IndicesFilter filter = null;
            if (nonMatching != null)
            {
                filter = new IndicesFilter(indices, matchingFilter, nonMatching);
            }                
            else
            {
                filter = new IndicesFilter(indices, matchingFilter, JsonConvert.DeserializeObject<IFilter>(fieldDict.GetString(_NON_MATCHING_FILTER)));
            }

            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            return filter;
        }
 public void FAIL_CreateQuery_Indices()
 {
     try
     {
         IndicesFilter filter = new IndicesFilter(null, null, NonMatchingTypeEnum.All);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("indices", argEx.ParamName);
     }
 }
 public void PASS_CreateQuery_None()
 {
     IndicesFilter filter = new IndicesFilter(
         new List<string>() { "1", "2", "3" },
         new TermFilter("field", "value"),
         NonMatchingTypeEnum.None);
     Assert.IsNotNull(filter);
     Assert.AreEqual(3, filter.Indices.Count());
     Assert.IsTrue(filter.MatchingFilter is TermFilter);
     Assert.AreEqual("field", (filter.MatchingFilter as TermFilter).Field);
     Assert.AreEqual("value", (filter.MatchingFilter as TermFilter).Value);
     Assert.AreEqual(NonMatchingTypeEnum.None, filter.NonMatchingFilterType);
 }
 public void FAIL_CreateQuery_MatchingFilter()
 {
     try
     {
         IndicesFilter filter = new IndicesFilter(
             new List<string>() { "1" },
             null,
             NonMatchingTypeEnum.All);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("matchingFilter", argEx.ParamName);
     }
 }
 public void FAIL_CreateQuery_NonMatchingFilter()
 {
     try
     {
         IndicesFilter filter = new IndicesFilter(
             new List<string>() { "1" },
             new TermFilter("field", "value"),
             (IFilter)null);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("nonMatchingFilter", argEx.ParamName);
     }
 }
        public void PASS_Serialize_Index()
        {
            IndicesFilter query = new IndicesFilter(
                new List<string>() { "1" },
                new TermFilter("field", "value"),
                new TermFilter("field", "value"));

            string result = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(result);

            string expectedJson = "{\"indices\":{\"index\":\"1\",\"filter\":{\"term\":{\"field\":\"value\"}},\"no_match_filter\":{\"term\":{\"field\":\"value\"}}}}";
            Assert.AreEqual(expectedJson, result);
        }