|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using FluentAssertions; |
| 4 | +using Nest; |
| 5 | +using Tests.Framework; |
| 6 | +using Tests.Framework.Integration; |
| 7 | +using Tests.Framework.ManagedElasticsearch.Clusters; |
| 8 | +using Tests.Framework.MockData; |
| 9 | + |
| 10 | +namespace Tests.Aggregations |
| 11 | +{ |
| 12 | + /** |
| 13 | + *=== Aggregation Metadata |
| 14 | + * Metadata can be provided per aggregation, and will be returned in the aggregation response |
| 15 | + */ |
| 16 | + public class AggregationMetaUsageTests : AggregationUsageTestBase |
| 17 | + { |
| 18 | + public AggregationMetaUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { } |
| 19 | + |
| 20 | + protected override object AggregationJson => new |
| 21 | + { |
| 22 | + min_last_activity = new |
| 23 | + { |
| 24 | + min = new |
| 25 | + { |
| 26 | + field = "lastActivity" |
| 27 | + }, |
| 28 | + meta = new |
| 29 | + { |
| 30 | + meta_1 = "value_1", |
| 31 | + meta_2 = 2, |
| 32 | + meta_3 = new |
| 33 | + { |
| 34 | + meta_3 = "value_3" |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + protected override Func<AggregationContainerDescriptor<Project>, IAggregationContainer> FluentAggs => a => a |
| 41 | + .Min("min_last_activity", m => m |
| 42 | + .Field(p => p.LastActivity) |
| 43 | + .Meta(d => d |
| 44 | + .Add("meta_1", "value_1") |
| 45 | + .Add("meta_2", 2) |
| 46 | + .Add("meta_3", new { meta_3 = "value_3" }) |
| 47 | + ) |
| 48 | + ); |
| 49 | + |
| 50 | + protected override AggregationDictionary InitializerAggs => |
| 51 | + new MinAggregation("min_last_activity", Infer.Field<Project>(p => p.LastActivity)) |
| 52 | + { |
| 53 | + Meta = new Dictionary<string,object> |
| 54 | + { |
| 55 | + { "meta_1", "value_1" }, |
| 56 | + { "meta_2", 2 }, |
| 57 | + { "meta_3", new { meta_3 = "value_3" } } |
| 58 | + } |
| 59 | + }; |
| 60 | + |
| 61 | + protected override void ExpectResponse(ISearchResponse<Project> response) |
| 62 | + { |
| 63 | + response.ShouldBeValid(); |
| 64 | + var min = response.Aggregations.Min("min_last_activity"); |
| 65 | + min.Meta.Should().NotBeNull().And.ContainKeys("meta_1", "meta_2", "meta_3"); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments