Пример #1
0
 public void PASS_CreateFilter()
 {
     TermFilter filter = new TermFilter("field", "value1");
     Assert.IsNotNull(filter);
     Assert.AreEqual("field", filter.Field);
     Assert.AreEqual("value1", filter.Value.ToString());
 }
Пример #2
0
        public void PASS_Serialize_Cache()
        {
            TermFilter filter = new TermFilter("field", "value") { Cache = false };
            string json = JsonConvert.SerializeObject(filter);
            Assert.IsNotNull(json);

            string expectedJson = "{\"term\":{\"field\":\"value\",\"_cache\":false}}";
            Assert.AreEqual(expectedJson, json);
        }
Пример #3
0
        public void PASS_Serialize()
        {
            TermFilter filter = new TermFilter("field", "value1");

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

            string expectedJson = "{\"term\":{\"field\":\"value1\"}}";
            Assert.AreEqual(expectedJson, result);
        }
Пример #4
0
 public void FAIL_CreateFilter_Value()
 {
     try
     {
         TermFilter filter = new TermFilter("field", null);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("value", argEx.ParamName);
     }
 }
Пример #5
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.First().Key.Equals(FilterTypeEnum.Term.ToString(), StringComparison.OrdinalIgnoreCase))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            KeyValuePair<string, object> fieldKvp = fieldDict.FirstOrDefault(x => !_KnownFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase));

            if(string.IsNullOrWhiteSpace(fieldKvp.Key))
                throw new RequiredPropertyMissingException("field");

            TermFilter filter = new TermFilter(fieldKvp.Key, fieldKvp.Value);
            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);
            return filter;
        }
Пример #6
0
        public void PASS_Serialize_Number()
        {
            TermFilter filter = new TermFilter("field", 15); ;
            string json = JsonConvert.SerializeObject(filter);
            Assert.IsNotNull(json);

            string expectedJson = "{\"term\":{\"field\":15}}";
            Assert.AreEqual(expectedJson, json);
        }