public void PASS_CreateQuery_Fields()
 {
     SimpleQueryStringQuery query = new SimpleQueryStringQuery(new List<string>(){"field"}, "term1 term2");
     Assert.IsNotNull(query);
     Assert.AreEqual(1, query.Fields.Count());
     Assert.AreEqual("term1 term2", query.Query);
 }
        public void PASS_Serialize()
        {
            SimpleQueryStringQuery query = new SimpleQueryStringQuery(new List<string>(){"field"}, "term1 term2");
            string json = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(json);

            string expectedJson = "{\"simple_query_string\":{\"fields\":[\"field\"],\"query\":\"term1 term2\"}}";
            Assert.AreEqual(expectedJson, json);
        }
 public void FAIL_CreateQuery_Fields()
 {
     try
     {
         SimpleQueryStringQuery query = new SimpleQueryStringQuery(null, "query");
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("fields", ex.ParamName);
     }
 }
        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(QueryTypeEnum.SimpleQueryString.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            SimpleQueryStringQuery query = null;
            string queryStr = fieldDict.GetString(_QUERY);
            if (fieldDict.ContainsKey(_FIELDS))
            {
                query = new SimpleQueryStringQuery(JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_FIELDS)), queryStr);
            }
            else 
            {
                query = new SimpleQueryStringQuery(queryStr);
            }

            query.Analyzer = fieldDict.GetStringOrDefault(_ANALYZER);
            query.DefaultOperator = OperatorEnum.Find(fieldDict.GetString(_DEFAULT_OPERATOR, _DEFAULT_OPERATOR_DEFAULT.ToString()));
            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);

            if (fieldDict.ContainsKey(_FLAGS))
            {
                string flagsValue = fieldDict.GetString(_FLAGS);
                if(!string.IsNullOrWhiteSpace(flagsValue))
                {
                    ParsingFeatureEnum feature = ParsingFeatureEnum.All;
                    List<ParsingFeatureEnum> features = new List<ParsingFeatureEnum>();
                    foreach (string flagValue in flagsValue.Split(_FLAG_DELIMITERS.ToArray(), StringSplitOptions.RemoveEmptyEntries))
                    {
                        feature = ParsingFeatureEnum.Find(flagValue);
                        if (feature == null)
                            throw new Exception("Unable to match " + flagValue + " to a parsing feature.");

                        features.Add(feature);
                    }

                    if (features.Any())
                        query.ParsingFeatureFlags = features;
                }                
            }

            return query;
        }
 public void PASS_CreateQuery_NoField()
 {
     SimpleQueryStringQuery query = new SimpleQueryStringQuery("term1 term2");
     Assert.IsNotNull(query);
     Assert.AreEqual("term1 term2", query.Query);
 }