public void PrefixElasticMethodCreatesPrefixWhereCriteria()
        {
            var where = Robots.Where(r => ElasticMethods.Prefix(r.Name, "robot"));
            var criteria = ElasticQueryTranslator.Translate(Mapping, "prefix", where.Expression).SearchRequest.Filter;

            Assert.IsType <PrefixCriteria>(criteria);
            var regexpCriteria = (PrefixCriteria)criteria;

            Assert.Equal("prefix", regexpCriteria.Name);
            Assert.Equal("prefix.name", regexpCriteria.Field);
            Assert.Equal("robot", regexpCriteria.Prefix);
        }
Example #2
0
        public void WhereElasticMethodsSelectAverageCreatesValidQuery()
        {
            var query = Robots
                        .Where(r => ElasticMethods.Prefix(r.Name, "abc"))
                        .GroupBy(r => r.Zone).Select(g => g.Average(r => r.EnergyUse));

            var translation = ElasticQueryTranslator.Translate(Mapping, "p", query.Expression);

            var prefixFilter = Assert.IsType <PrefixCriteria>(translation.SearchRequest.Filter);

            Assert.Equal("abc", prefixFilter.Prefix);
            Assert.Equal("p.name", prefixFilter.Field);

            Assert.Equal(typeof(double), Assert.IsType <ListTermFacetsElasticMaterializer>(translation.Materializer).ElementType);
            Assert.Equal("count", translation.SearchRequest.SearchType);
            Assert.Equal(1, translation.SearchRequest.Facets.Count);

            var facet = Assert.IsType <TermsStatsFacet>(translation.SearchRequest.Facets[0]);

            Assert.Null(facet.Filter);
            Assert.Equal("p.zone", facet.Key);
            Assert.Equal("p.energyUse", facet.Value);
        }
Example #3
0
        public static void PrefixMustBeBetweenMemberAndConstant()
        {
            const string expectedMessageFragment = "Prefix must take a member";

            {
                var ex = Assert.Throws <NotSupportedException>(() => Translate(Robots.Where(r => ElasticMethods.Prefix(r.Name, r.Name))));
                Assert.Contains(expectedMessageFragment, ex.Message);
            }

            {
                var ex = Assert.Throws <NotSupportedException>(() => Translate(Robots.Where(r => ElasticMethods.Prefix("", r.Name))));
                Assert.Contains(expectedMessageFragment, ex.Message);
            }

            {
                var ex = Assert.Throws <NotSupportedException>(() => Translate(Robots.Where(r => ElasticMethods.Prefix("", ""))));
                Assert.Contains(expectedMessageFragment, ex.Message);
            }
        }
Example #4
0
 [ExcludeFromCodeCoverage] // Expression isn't "executed"
 public void PrefixThrowsIfAccessed()
 {
     Assert.Throws <InvalidOperationException>(() => ElasticMethods.Prefix("a", "b"));
 }
        public void PrefixThrowsIfAccessed()
        {
            var ex = Assert.Throws <InvalidOperationException>(() => ElasticMethods.Prefix("a", "b"));

            Assert.Contains("ElasticMethods.Prefix", ex.Message);
        }