public void FAIL_CreateQuery_NoFilters()
 {
     try
     {
         BoolFilter query = new BoolFilter(null, null, null);
         Assert.Fail();
     }
     catch (ArgumentNullException argEx)
     {
         Assert.AreEqual("filters", argEx.ParamName);
     }
 }
        public void FAIL_CreateFilter_MinimumShouldMatch()
        {
            List<IFilter> mustFilters = new List<IFilter>
            {
                new TermFilter("field", "value1"),
                new TermFilter("field", "value2")
            };

            try
            {
                BoolFilter query = new BoolFilter(mustFilters, null, null)
                {
                    MinimumShouldMatch = new IntegerMatch(0)
                };
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException argEx)
            {
                Assert.AreEqual("value", argEx.ParamName);
            }
        }
        public void PASS_CreateFilter()
        {
            List<IFilter> mustFilters = new List<IFilter>
            {
                new TermFilter("field", "value1"),
                new TermFilter("field", "value2")
            };

            List<IFilter> mustNotFilters = new List<IFilter>()
            {
                new TermFilter("field", "value3")
            };

            List<IFilter> shouldFilters = new List<IFilter>()
            {
                new TermFilter("field", "value4"),
                new TermFilter("field", "value5")
            };

            BoolFilter query = new BoolFilter(mustFilters, mustNotFilters, shouldFilters);

            Assert.IsNotNull(query);
        }
        public void PASS_Serialize_Terms()
        {
            List<IFilter> mustFilters = new List<IFilter>
            {
                new TermFilter("field", "value1"),
                new TermFilter("field", "value2")
            };

            List<IFilter> mustNotFilters = new List<IFilter>()
            {
                new TermFilter("field", "value3")
            };

            List<IFilter> shouldFilters = new List<IFilter>()
            {
                new TermFilter("field", "value4"),
                new TermFilter("field", "value5")
            };

            BoolFilter query = new BoolFilter(mustFilters, mustNotFilters, shouldFilters);

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

            string expectedResult = "{\"bool\":{\"must\":[{\"term\":{\"field\":\"value1\"}},{\"term\":{\"field\":\"value2\"}}],\"must_not\":[{\"term\":{\"field\":\"value3\"}}],\"should\":[{\"term\":{\"field\":\"value4\"}},{\"term\":{\"field\":\"value5\"}}]}}";

            Assert.AreEqual(expectedResult, result);
        }