예제 #1
0
 public void PASS_CreateFilter_Terms()
 {
     TermsFilter filter = new TermsFilter("field", new List<object>() { "1", "2" });
     Assert.IsNotNull(filter);
     Assert.AreEqual("field", filter.Field);
     Assert.AreEqual(2, filter.Terms.Count());
 }
예제 #2
0
 public void PASS_CreateFilter_IndexedTerms()
 {
     TermsFilter filter = new TermsFilter("field", "index", "type", "id", "path");
     Assert.IsNotNull(filter);
     Assert.AreEqual("field", filter.Field);
     Assert.AreEqual("index", filter.Index);
     Assert.AreEqual("type", filter.DocumentType);
     Assert.AreEqual("id", filter.DocumentId);
     Assert.AreEqual("path", filter.Path);
 }
예제 #3
0
 public void FAIL_CreateFilter_IndexTerms_DocumentType()
 {
     try
     {
         TermsFilter filter = new TermsFilter("field", "index", "", "id", "path");
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("documentType", ex.ParamName);
     }
 }
예제 #4
0
 public void FAIL_CreateFilter_Terms_Terms()
 {
     try
     {
         TermsFilter filter = new TermsFilter("field", null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("terms", ex.ParamName);
     }
 }
예제 #5
0
 public void FAIL_CreateFilter_Terms_Field()
 {
     try
     {
         TermsFilter filter = new TermsFilter(null, new List<object>() { "1", "2" });
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("field", ex.ParamName);
     }
 }
예제 #6
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.Terms.ToString()) || fieldDict.ContainsKey(FilterTypeEnum.In.ToString()))
                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");

            TermsFilter filter = null;
            Dictionary<string, object> indexTermsDict = null;
            try
            {
                indexTermsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldKvp.Value.ToString());
            }
            catch
            {
                filter = new TermsFilter(fieldKvp.Key, JsonConvert.DeserializeObject<IEnumerable<object>>(fieldKvp.Value.ToString()));
                filter.ExecutionType = ExecutionTypeEnum.Find(fieldDict.GetString(_EXECUTION, _EXECUTION_DEFAULT.ToString()));
                FilterSerializer.DeserializeBaseValues(filter, filter.ExecutionType.CacheDefault, fieldDict);
                return filter;
            }

            filter = new TermsFilter(fieldKvp.Key,
                                indexTermsDict.GetString(_INDEX),
                                indexTermsDict.GetString(_TYPE),
                                indexTermsDict.GetString(_ID),
                                indexTermsDict.GetString(_PATH));

            filter.Routing = indexTermsDict.GetStringOrDefault(_ROUTING);
            FilterSerializer.DeserializeBaseValues(filter, _INDEXED_TERMS_CACHE_DEFAULT, fieldDict);

            return filter;
        }
예제 #7
0
        public void PASS_Serialize_IndexedTerms()
        {
            TermsFilter filter = new TermsFilter("field", "index", "type", "id", "path") { CacheKey = "cache_key"};
            string json = JsonConvert.SerializeObject(filter);
            Assert.IsNotNull(json);
            string expectedJson = "{\"terms\":{\"field\":{\"index\":\"index\",\"type\":\"type\",\"id\":\"id\",\"path\":\"path\"},\"_cache_key\":\"cache_key\"}}";

            Assert.AreEqual(expectedJson, json);
        }
예제 #8
0
 public void PASS_Serialize_Terms_BoolNoCache()
 {
     TermsFilter filter = new TermsFilter("field", new List<object>() { "1", "2" }) { ExecutionType = ExecutionTypeEnum.BoolNoCache };
     string json = JsonConvert.SerializeObject(filter);
     Assert.IsNotNull(json);
     string expectedJson = "{\"terms\":{\"field\":[\"1\",\"2\"],\"execution\":\"bool_nocache\",\"_cache\":true}}";
     Assert.AreEqual(expectedJson, json);
 }