public static void WithElasticQuery_ToElasticSearchQuery_ReturnsJSON() { var query = new TestableElasticContext().Query <Sample>(); var result = query.Where(x => x.Property == "2112").ToElasticSearchQuery(); Assert.Equal(@"{""filter"":{""term"":{""property"":""2112""}}}", result); }
public static void HighlightQuery_ReturnsJSON_CallChain() { var body = new TestableElasticContext().Query <MultiPropertySample>() .Highlight(e => e.Property1) .Highlight(e => e.Property2) .ToQueryInfo().Query; Assert.Contains("\"fields\":{\"property2\":{},\"property1\":{}}", body); }
public static void CustomTypes_Terms() { var context = new TestableElasticContext(); var identifiers = new[] { new Identifier("vALue1"), new Identifier("ValuE2") }; var query = context.Query <ClassWithIdentifier>().Where(x => identifiers.Contains(x.id)).ToElasticSearchQuery(); // Also verifies that any value which gets JSON converted into a string gets lower-cased Assert.Equal(@"{""filter"":{""terms"":{""id"":[""value1!!"",""value2!!""]}}}", query); }
public static void CustomTypes_Term() { var context = new TestableElasticContext(new MyCustomMapping()); var helloIdentifier = new Identifier("Hello"); var query = context.Query <ClassWithIdentifier>().Where(x => x.id == helloIdentifier).ToElasticSearchQuery(); // Also verifies that any value which gets JSON converted into a string gets lower-cased Assert.Equal(@"{""filter"":{""term"":{""docWrapper.classWithIdentifier.id"":""hello!!""}}}", query); }
public static void CustomTypes_Terms() { var context = new TestableElasticContext(new ElasticMapping(lowerCaseAnalyzedFieldValues: true)); var identifiers = new[] { new Identifier("vALue1"), new Identifier("ValuE2") }; var queryInfo = context.Query <ClassWithIdentifier>().Where(x => identifiers.Contains(x.id)).ToQueryInfo(); // Also verifies that any value which gets JSON converted into a string gets lower-cased Assert.Equal(@"{""query"":{""terms"":{""id"":[""value1!!"",""value2!!""]}}}", queryInfo.Query); }
public static void HighlightQuery_ReturnsJSON_CallChain_ConfigInLast() { var body = new TestableElasticContext().Query <MultiPropertySample>() .Highlight(e => e.Property1, new Highlight { PreTag = "<a>" }) .Highlight(e => e.Property2, new Highlight { PreTag = "<b>", PostTag = "<c>" }) .ToQueryInfo().Query; Assert.Contains("\"pre_tags\":[\"<b>\"]", body); Assert.Contains("\"post_tags\":[\"<c>\"]", body); Assert.DoesNotContain("\"pre_tags\":[\"<a>\"]", body); }
public TestableElasticQuery(TestableElasticContext context, Expression expression = null) { Context = context; ElementType = typeof(T); Expression = expression ?? Expression.Constant(context.Data <T>().AsQueryable()); }
/// <summary> /// Initializes a new instance of the <see cref="TestableElasticQueryProvider"/> class. /// </summary> /// <param name="context">The <see cref="TestableElasticContext"/> used to execute the queries.</param> public TestableElasticQueryProvider(TestableElasticContext context) { this.context = context; }