-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed hardcoded values in tests for #1121 and small indendation tou…
…chups
- Loading branch information
Showing
3 changed files
with
87 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 59 additions & 54 deletions
113
src/Tests/Nest.Tests.Integration/Aggregations/FIltersAggregationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,73 @@ | ||
using FluentAssertions; | ||
using Nest.Tests.MockData; | ||
using Nest.Tests.MockData.Domain; | ||
using NUnit.Framework; | ||
|
||
namespace Nest.Tests.Integration.Aggregations | ||
{ | ||
[TestFixture] | ||
public class FiltersAggregationTests : IntegrationTests | ||
{ | ||
[Test] | ||
public void NamedFilters() | ||
{ | ||
var results = this.Client.Search<ElasticsearchProject>(s => s | ||
.Size(0) | ||
.Aggregations(a => a | ||
.Filters("filtersAggregation", | ||
t => | ||
t.Filters(x => x.Name("first").Term(p => p.Name, "pyelasticsearch"), | ||
x => x.Name("second").Term(p => p.Country, "Sweden")) | ||
.Aggregations(n => n.Average("avg", d => d.Field(x => x.Id))) | ||
) | ||
) | ||
); | ||
[TestFixture] | ||
public class FiltersAggregationTests : IntegrationTests | ||
{ | ||
private readonly string _indexedName = NestTestData.Data[3].Name; | ||
private readonly string _indexedCountry = NestTestData.Data[2].Country; | ||
[Test] | ||
public void NamedFilters() | ||
{ | ||
|
||
results.IsValid.Should().BeTrue(); | ||
var filtersBuckets = results.Aggs.Filters("filtersAggregation"); | ||
filtersBuckets.Should().NotBeNull(); | ||
filtersBuckets.Aggregations.Should().NotBeNull(); | ||
var results = this.Client.Search<ElasticsearchProject>(s => s | ||
.Size(0) | ||
.Aggregations(a => a | ||
.Filters("filtersAggregation", t => t | ||
.Filters( | ||
x => x.Name("first").Term(p => p.Name.Suffix("sort"), _indexedName), | ||
x => x.Name("second").Term(p => p.Country, _indexedCountry) | ||
) | ||
.Aggregations(n => n.Average("avg", d => d.Field(x => x.Id))) | ||
) | ||
) | ||
); | ||
|
||
var firstBucket = filtersBuckets.Aggregations.Global("first"); | ||
firstBucket.Should().NotBeNull(); | ||
var firstCount = firstBucket.DocCount; | ||
firstCount.ShouldBeEquivalentTo(1); | ||
results.IsValid.Should().BeTrue(); | ||
var filtersBuckets = results.Aggs.Filters("filtersAggregation"); | ||
filtersBuckets.Should().NotBeNull(); | ||
filtersBuckets.Aggregations.Should().NotBeNull(); | ||
|
||
var secondBucket = filtersBuckets.Aggregations.Global("second"); | ||
secondBucket.Should().NotBeNull(); | ||
var secondCount = secondBucket.DocCount; | ||
secondCount.ShouldBeEquivalentTo(2); | ||
} | ||
var firstBucket = filtersBuckets.Aggregations.Global("first"); | ||
firstBucket.Should().NotBeNull(); | ||
firstBucket.DocCount.Should().BeGreaterOrEqualTo(1); | ||
|
||
[Test] | ||
public void AnonymousFilters() | ||
{ | ||
var results = this.Client.Search<ElasticsearchProject>(s => s | ||
.Size(0) | ||
.Aggregations(a => a | ||
.Filters("filtersAggregation", | ||
t => | ||
t.Filters(x => x.Term(p => p.Name, "pyelasticsearch"), x => x.Term(p => p.Country, "Sweden")) | ||
.Aggregations(n => n.Average("avg", d => d.Field(x => x.Id))) | ||
) | ||
) | ||
); | ||
var secondBucket = filtersBuckets.Aggregations.Global("second"); | ||
secondBucket.Should().NotBeNull(); | ||
var secondCount = secondBucket.DocCount; | ||
secondCount.Should().BeGreaterOrEqualTo(1); | ||
} | ||
|
||
results.IsValid.Should().BeTrue(); | ||
var filtersBuckets = results.Aggs.Filters("filtersAggregation"); | ||
filtersBuckets.Should().NotBeNull(); | ||
filtersBuckets.Items.Should().NotBeNull(); | ||
[Test] | ||
public void AnonymousFilters() | ||
{ | ||
var results = this.Client.Search<ElasticsearchProject>(s => s | ||
.Size(0) | ||
.Aggregations(a => a | ||
.Filters("filtersAggregation", t => t | ||
.Filters( | ||
x => x.Term(p => p.Name.Suffix("sort"), _indexedName), | ||
x => x.Term(p => p.Country, _indexedCountry) | ||
) | ||
.Aggregations(n => n.Average("avg", d => d.Field(x => x.Id))) | ||
) | ||
) | ||
); | ||
|
||
var buckets = filtersBuckets.Items; | ||
buckets.Should().NotBeNull() | ||
.And.HaveCount(2) | ||
.And.Contain(a => (a as SingleBucket).DocCount == 1) | ||
.And.Contain(a => (a as SingleBucket).DocCount == 2); | ||
results.IsValid.Should().BeTrue(); | ||
var filtersBuckets = results.Aggs.Filters("filtersAggregation"); | ||
filtersBuckets.Should().NotBeNull(); | ||
filtersBuckets.Items.Should().NotBeNull(); | ||
|
||
} | ||
} | ||
var buckets = filtersBuckets.Items; | ||
buckets.Should().NotBeNull() | ||
.And.HaveCount(2) | ||
.And.OnlyContain(a => (a as SingleBucket).DocCount >= 1); | ||
|
||
} | ||
} | ||
} |