public void ToStringContainsFieldComparisonAndValue()
        {
            var criteria = new ExistsCriteria("thisIsAMissingField");
            var result = criteria.ToString();

            Assert.Contains(criteria.Field, result);
        }
        public void ConstructorSetsCriteria()
        {
            const string field = "myField";

            var criteria = new ExistsCriteria(field);

            Assert.Equal(field, criteria.Field);
        }
        public void OrWithOrWithTrueOptimizesToTrue()
        {
            var exists1 = new ExistsCriteria("1");
            var exists2 = new ExistsCriteria("2");
            var criteria = OrCriteria.Combine(exists1, OrCriteria.Combine(ConstantCriteria.True, exists2));

            var actual = ConstantCriteriaFilterReducer.Reduce(criteria);

            Assert.Same(ConstantCriteria.True, actual);
        }
        public void AndWithFalseOptimizesToFalse()
        {
            var exists1 = new ExistsCriteria("1");
            var exists2 = new ExistsCriteria("2");
            var criteria = AndCriteria.Combine(exists1, ConstantCriteria.False, exists2);

            var actual = ConstantCriteriaFilterReducer.Reduce(criteria);

            Assert.Same(ConstantCriteria.False, actual);
        }
        public void BodyContainsFilterExists()
        {
            const string expectedFieldName = "fieldShouldExist";
            var existsCriteria = new ExistsCriteria(expectedFieldName);

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

            var field = body.TraverseWithAssert("query", "filtered", "filter", "exists", "field");
            Assert.Equal(expectedFieldName, field);
        }
        public void BodyContainsFilterFacet()
        {
            var expectedFilter = new ExistsCriteria("IsLocal");
            var expectedFacet = new FilterFacet("LocalSales", expectedFilter);
            var searchRequest = new SearchRequest { Facets = new List<IFacet>(new[] { expectedFacet }) };

            var formatter = new SearchRequestFormatter(defaultConnection, mapping, searchRequest);
            var body = JObject.Parse(formatter.Body);

            var result = body.TraverseWithAssert("facets", expectedFacet.Name, expectedFacet.Type, expectedFilter.Name, "field");
            Assert.Equal(expectedFilter.Field, result.ToString());
        }
        public void AndWithTrueRemovesTrue()
        {
            var exists1 = new ExistsCriteria("1");
            var exists2 = new ExistsCriteria("2");
            var criteria = AndCriteria.Combine(exists1, ConstantCriteria.True, exists2);

            var actual = ConstantCriteriaFilterReducer.Reduce(criteria);

            var andActual = Assert.IsType<AndCriteria>(actual);
            Assert.DoesNotContain(andActual.Criteria, c => c == ConstantCriteria.True);
            Assert.Single(andActual.Criteria, exists1);
            Assert.Single(andActual.Criteria, exists2);
        }
        public void OrWithFalseRemovesFalse()
        {
            var exists1 = new ExistsCriteria("1");
            var exists2 = new ExistsCriteria("2");
            var criteria = OrCriteria.Combine(exists1, ConstantCriteria.False, exists2);

            var actual = ConstantCriteriaFilterReducer.Reduce(criteria);

            var orActual = Assert.IsType<OrCriteria>(actual);
            Assert.DoesNotContain(orActual.Criteria, c => c == ConstantCriteria.False);
            Assert.Single(orActual.Criteria, exists1);
            Assert.Single(orActual.Criteria, exists2);
        }
        public void NamePropertyIsExists()
        {
            var criteria = new ExistsCriteria("something");

            Assert.Equal("exists", criteria.Name);
        }
Example #10
0
        public void ToStringContainsSubfields()
        {
            var existsCriteria = new ExistsCriteria("thisIsAMissingField");
            var termCriteria = TermsCriteria.Build("termField", memberInfo, "some value");

            var orCriteria = OrCriteria.Combine(existsCriteria, termCriteria);
            var result = orCriteria.ToString();

            Assert.Contains(existsCriteria.ToString(), result);
            Assert.Contains(termCriteria.ToString(), result);
        }
        public void BodyContainsFilterSingleCollapsedOr()
        {
            const string expectedFieldName = "fieldShouldExist";
            var existsCriteria = new ExistsCriteria(expectedFieldName);
            var orCriteria = OrCriteria.Combine(existsCriteria);

            var formatter = new PostBodyRequestFormatter(defaultConnection, mapping, new ElasticSearchRequest { Type = "type1", Filter = orCriteria });
            var body = JObject.Parse(formatter.Body);

            var field = TraverseWithAssert(body, "filter", "exists", "field");
            Assert.Equal(expectedFieldName, field);
        }