コード例 #1
0
        public void QueryAndWhereGeneratesQueryAndFilterCriteria()
        {
            var query = Robots.Query(r => ElasticMethods.Regexp(r.Name, "r.*bot")).Where(r => r.Zone.HasValue);

            var searchRequest = ElasticQueryTranslator.Translate(Mapping, "prefix", query.Expression).SearchRequest;

            Assert.IsType <RegexpCriteria>(searchRequest.Query);
            Assert.IsType <ExistsCriteria>(searchRequest.Filter);
        }
コード例 #2
0
        public void RegexElasticMethodCreatesRegexWhereCriteria()
        {
            var where = Robots.Where(r => ElasticMethods.Regexp(r.Name, "r.*bot"));
            var criteria = ElasticQueryTranslator.Translate(Mapping, "prefix", where.Expression).SearchRequest.Filter;

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

            Assert.Equal("regexp", regexpCriteria.Name);
            Assert.Equal("prefix.name", regexpCriteria.Field);
            Assert.Equal("r.*bot", regexpCriteria.Regexp);
        }
コード例 #3
0
        public static void RegexpMustBeBetweenMemberAndConstant()
        {
            const string expectedMessageFragment = "Regexp must take a member";

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

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

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

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