public void PASS_Serialize()
 {
     PrefixFilter filter = new PrefixFilter("field", "value");
     string json = JsonConvert.SerializeObject(filter);
     Assert.IsNotNull(json);
     string expectedJson = "{\"prefix\":{\"field\":\"value\"}}";
     Assert.AreEqual(expectedJson, json);
 }
 public void FAIL_CreateFilter_Value()
 {
     try
     {
         PrefixFilter filter = new PrefixFilter("field", null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("value", ex.ParamName);
     }
 }
예제 #3
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.Prefix.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            KeyValuePair<string, object> fieldKvp = fieldDict.First(x => !_KnownFields.Contains(x.Key));
            if (string.IsNullOrWhiteSpace(fieldKvp.Key))
                throw new RequiredPropertyMissingException("field");

            PrefixFilter filter = new PrefixFilter(fieldKvp.Key, fieldKvp.Value.ToString());
            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            return filter;
        }
 public void PASS_CreateFilter()
 {
     PrefixFilter filter = new PrefixFilter("field", "value");
     Assert.AreEqual("field", filter.Field);
     Assert.AreEqual("value", filter.Value);
 }