Ejemplo n.º 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());
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public void FAIL_CreateFilter_Value()
 {
     try
     {
         TermFilter filter = new TermFilter("field", null);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("value", argEx.ParamName);
     }
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }