public void PASS_Serialize_Cache()
 {
     OrFilter filter = new OrFilter(new List<IFilter>() { new TermFilter("field", "value") }) { Cache = true };
     string json = JsonConvert.SerializeObject(filter);
     Assert.IsNotNull(json);
     string expectedJson = "{\"or\":{\"filters\":[{\"term\":{\"field\":\"value\"}}],\"_cache\":true}}";
     Assert.AreEqual(expectedJson, json);
 }
 public void PASS_CreateFilter()
 {
     OrFilter filter = new OrFilter(new List<IFilter>() { new TermFilter("field", "value") });
     Assert.IsNotNull(filter);
     Assert.AreEqual(false, filter.Cache);
     Assert.AreEqual(null, filter.CacheKey);
     Assert.IsTrue(filter.Filters.First() is TermFilter);
     TermFilter termFilter = filter.Filters.First() as TermFilter;
     Assert.AreEqual("field", termFilter.Field);
     Assert.AreEqual("value", termFilter.Value);
 }
 public void FAIL_CreateFilter()
 {
     try
     {
         OrFilter filter = new OrFilter(null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("filters", ex.ParamName);
     }
 }
Beispiel #4
0
        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.Or.ToString()))
            {
                try
                {
                    fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());
                }
                catch
                {
                    return new OrFilter(JsonConvert.DeserializeObject<IEnumerable<IFilter>>(fieldDict.First().Value.ToString()));
                }
            }

            OrFilter filter = new OrFilter(JsonConvert.DeserializeObject<IEnumerable<IFilter>>(fieldDict.GetString(_FILTERS)));
            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            return filter;
        }