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); }
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); }
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); } }
[ExcludeFromCodeCoverage] // Expression isn't "executed" public void RegexpThrowsIfAccessed() { Assert.Throws <InvalidOperationException>(() => ElasticMethods.Regexp("a", "b")); }
public void RegexpThrowsIfAccessed() { var ex = Assert.Throws <InvalidOperationException>(() => ElasticMethods.Regexp("a", "b")); Assert.Contains("ElasticMethods.Regexp", ex.Message); }