Skip to content

Commit

Permalink
WIP: Fix test compiler errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Sep 12, 2024
1 parent 1175b50 commit 020968c
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 225 deletions.
106 changes: 53 additions & 53 deletions tests/Foundatio.Parsers.ElasticQueries.Tests/AggregationParserTests.cs

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch.QueryDsl;
using Foundatio.Parsers.ElasticQueries.Extensions;
using Foundatio.Parsers.LuceneQueries.Nodes;
using Foundatio.Parsers.LuceneQueries.Visitors;
Expand All @@ -15,26 +16,26 @@ public class CustomVisitorTests : ElasticsearchTestBase
{
public CustomVisitorTests(ITestOutputHelper output, ElasticsearchFixture fixture) : base(output, fixture)
{
Log.DefaultMinimumLevel = Microsoft.Extensions.Logging.LogLevel.Trace;
Log.DefaultMinimumLevel = LogLevel.Trace;
}

[Fact]
public async Task CanResolveSimpleCustomFilter()
{
string index = CreateRandomIndex<MyType>();
Client.Index(new MyType { Id = "1" }, i => i.Index(index));
await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index));

var processor = new ElasticQueryParser(c => c
.SetLoggerFactory(Log)
.AddVisitor(new IncludeVisitor())
.AddVisitor(new CustomFilterVisitor()));

var result = await processor.BuildQueryAsync("@custom:(one)");
var actualResponse = Client.Search<MyType>(d => d.Index(index).Query(_ => result));
var actualResponse = await Client.SearchAsync<MyType>(d => d.Index(index).Query(_ => result));
string actualRequest = actualResponse.GetRequest();
_logger.LogInformation("Actual: {Request}", actualRequest);

var expectedResponse = Client.Search<MyType>(d => d
var expectedResponse = await Client.SearchAsync<MyType>(d => d
.Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Terms(m => m.Field("id").Terms("1"))))));
string expectedRequest = expectedResponse.GetRequest();
_logger.LogInformation("Expected: {Request}", expectedRequest);
Expand All @@ -47,19 +48,19 @@ public async Task CanResolveSimpleCustomFilter()
public async Task CanResolveCustomFilterContainingIncludes()
{
string index = CreateRandomIndex<MyType>();
Client.Index(new MyType { Id = "1" }, i => i.Index(index));
await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index));

var processor = new ElasticQueryParser(c => c
.SetLoggerFactory(Log)
.AddVisitor(new IncludeVisitor())
.AddVisitor(new CustomFilterVisitor()));

var result = await processor.BuildQueryAsync("@custom:(one @include:3)");
var actualResponse = Client.Search<MyType>(d => d.Index(index).Query(_ => result));
var actualResponse = await Client.SearchAsync<MyType>(d => d.Index(index).Query(_ => result));
string actualRequest = actualResponse.GetRequest();
_logger.LogInformation("Actual: {Request}", actualRequest);

var expectedResponse = Client.Search<MyType>(d => d
var expectedResponse = await Client.SearchAsync<MyType>(d => d
.Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Terms(m => m.Field("id").Terms("1", "3"))))));
string expectedRequest = expectedResponse.GetRequest();
_logger.LogInformation("Expected: {Request}", expectedRequest);
Expand All @@ -72,19 +73,19 @@ public async Task CanResolveCustomFilterContainingIncludes()
public async Task CanResolveIncludeToCustomFilterContainingIgnoredInclude()
{
string index = CreateRandomIndex<MyType>();
Client.Index(new MyType { Id = "1" }, i => i.Index(index));
await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index));

var processor = new ElasticQueryParser(c => c
.SetLoggerFactory(Log)
.UseIncludes(include => ResolveIncludeAsync("test", include, "@custom:(one @include:3)"), ShouldSkipInclude, 0)
.AddVisitor(new CustomFilterVisitor(), 1));

var result = await processor.BuildQueryAsync("@include:test");
var actualResponse = Client.Search<MyType>(d => d.Index(index).Query(_ => result));
var actualResponse = await Client.SearchAsync<MyType>(d => d.Index(index).Query(_ => result));
string actualRequest = actualResponse.GetRequest();
_logger.LogInformation("Actual: {Request}", actualRequest);

var expectedResponse = Client.Search<MyType>(d => d
var expectedResponse = await Client.SearchAsync<MyType>(d => d
.Index(index).Query(f => f.Bool(b => b.Filter(filter => filter.Terms(m => m.Field("id").Terms("1", "3"))))));
string expectedRequest = expectedResponse.GetRequest();
_logger.LogInformation("Expected: {Request}", expectedRequest);
Expand Down Expand Up @@ -119,19 +120,19 @@ private static Task<string> ResolveIncludeAsync(string expected, string actual,
public async Task CanResolveMultipleCustomFilters()
{
string index = CreateRandomIndex<MyType>();
Client.Index(new MyType { Id = "1" }, i => i.Index(index));
await Client.IndexAsync(new MyType { Id = "1" }, i => i.Index(index));

var processor = new ElasticQueryParser(c => c
.SetLoggerFactory(Log)
.AddVisitor(new IncludeVisitor())
.AddVisitor(new CustomFilterVisitor()));

var result = await processor.BuildQueryAsync("@custom:(one) OR (field1:Test @custom:(two))");
var actualResponse = Client.Search<MyType>(d => d.Index(index).Query(_ => result));
var actualResponse = await Client.SearchAsync<MyType>(d => d.Index(index).Query(_ => result));
string actualRequest = actualResponse.GetRequest();
_logger.LogInformation("Actual: {Request}", actualRequest);

var expectedResponse = Client.Search<MyType>(d => d.Index(index)
var expectedResponse = await Client.SearchAsync<MyType>(d => d.Index(index)
.Query(f => f
.Bool(b => b
.Filter(filter => filter
Expand Down Expand Up @@ -170,7 +171,7 @@ public override async Task VisitAsync(GroupNode node, IQueryVisitorContext conte
{
string term = ToTerm(node);
var ids = await GetIdsAsync(term);
if (ids != null && ids.Count > 0)
if (ids is { Count: > 0 })
node.Parent.SetQuery(new TermsQuery { Field = "id", Terms = ids });

Check failure on line 175 in tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs

View workflow job for this annotation

GitHub Actions / build / build

'TermsQuery' does not contain a definition for 'Terms'
else
node.Parent.SetQuery(new TermQuery { Field = "id", Value = "none" });

Check failure on line 177 in tests/Foundatio.Parsers.ElasticQueries.Tests/CustomVisitorTests.cs

View workflow job for this annotation

GitHub Actions / build / build

There is no argument given that corresponds to the required parameter 'field' of 'TermQuery.TermQuery(Field)'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
using Elastic.Clients.Elasticsearch.Mapping;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -27,11 +30,11 @@ private TypeMapping MapMyNestedType(TypeMappingDescriptor<MyNestedType> m)
}

[Fact]
public void CanResolveCodedProperty()
public async Task CanResolveCodedProperty()
{
string index = CreateRandomIndex<MyNestedType>(MapMyNestedType);

Client.IndexMany([
await Client.IndexManyAsync([
new MyNestedType
{
Field1 = "value1",
Expand All @@ -52,7 +55,8 @@ public void CanResolveCodedProperty()
new MyNestedType { Field1 = "value2", Field2 = "value2" },
new MyNestedType { Field1 = "value1", Field2 = "value4" }
], index);
Client.Indices.Refresh(index);

await Client.Indices.RefreshAsync(index);

var resolver = ElasticMappingResolver.Create<MyNestedType>(MapMyNestedType, Client, index, _logger);

Expand All @@ -62,11 +66,11 @@ public void CanResolveCodedProperty()
}

[Fact]
public void CanResolveProperties()
public async Task CanResolveProperties()
{
string index = CreateRandomIndex<MyNestedType>(MapMyNestedType);

Client.IndexMany([
await Client.IndexManyAsync([
new MyNestedType
{
Field1 = "value1",
Expand All @@ -87,7 +91,7 @@ public void CanResolveProperties()
new MyNestedType { Field1 = "value2", Field2 = "value2" },
new MyNestedType { Field1 = "value1", Field2 = "value4" }
], index);
Client.Indices.Refresh(index);
await Client.Indices.RefreshAsync(index);

var resolver = ElasticMappingResolver.Create<MyNestedType>(MapMyNestedType, Client, index, _logger);

Expand Down
Loading

0 comments on commit 020968c

Please sign in to comment.