public void BodyContainsBoolMustQuery()
        {
            var rangeCriteria = new RangeCriteria("ranged", memberInfo, RangeComparison.GreaterThanOrEqual, 88);
            var boolMust = new BoolCriteria(new[] { rangeCriteria }, null, null);

            var formatter = new SearchRequestFormatter(defaultConnection, mapping, new SearchRequest { DocumentType = "type1", Query = boolMust });
            var body = JObject.Parse(formatter.Body);

            var mustItems = body.TraverseWithAssert("query", "bool", "must");
            Assert.Equal(1, mustItems.Count());
            mustItems[0].TraverseWithAssert("range");
        }
        public void BodyContainsBoolShouldQuery()
        {
            var range1 = new RangeCriteria("range1", memberInfo, RangeComparison.GreaterThanOrEqual, 88);
            var range2 = new RangeCriteria("range2", memberInfo, RangeComparison.GreaterThanOrEqual, 88);
            var boolMust = new BoolCriteria(null, new[] { range1, range2 }, null);

            var formatter = new SearchRequestFormatter(defaultConnection, mapping, new SearchRequest { DocumentType = "type1", Query = boolMust });
            var body = JObject.Parse(formatter.Body);

            var boolBody = body.TraverseWithAssert("query", "bool");

            var minMatch = boolBody.TraverseWithAssert("minimum_should_match");
            Assert.Equal(1, minMatch.Value<int>());

            var mustNotItems = boolBody.TraverseWithAssert("should");
            Assert.Equal(2, mustNotItems.Count());
            mustNotItems[0].TraverseWithAssert("range");
        }
        IEnumerable<JProperty> BuildProperties(BoolCriteria criteria)
        {
            if (criteria.Must.Any())
                yield return new JProperty("must", new JArray(criteria.Must.Select(Build)));

            if (criteria.MustNot.Any())
                yield return new JProperty("must_not", new JArray(criteria.MustNot.Select(Build)));

            if (criteria.Should.Any())
            {
                yield return new JProperty("should", new JArray(criteria.Should.Select(Build)));
                yield return new JProperty("minimum_should_match", 1);
            }
        }
 JObject Build(BoolCriteria criteria)
 {
     return new JObject(new JProperty(criteria.Name, new JObject(BuildProperties(criteria))));
 }