From 2f8564149c43a79c8c4cb719b15e8dfb4498c983 Mon Sep 17 00:00:00 2001 From: Mauricio Scheffer Date: Tue, 20 Jan 2015 17:40:58 +0000 Subject: [PATCH] Expose constructor with inner aggregation dictionary --- .../Aggregations/BucketAggregationBase.cs | 8 +++--- src/Nest/Domain/Aggregations/SingleBucket.cs | 9 +++++-- .../Nest.Tests.Unit/Nest.Tests.Unit.csproj | 1 + .../SingleBucketAggregationTests.cs | 26 +++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/Tests/Nest.Tests.Unit/Search/Aggregations/SingleBucketAggregationTests.cs diff --git a/src/Nest/Domain/Aggregations/BucketAggregationBase.cs b/src/Nest/Domain/Aggregations/BucketAggregationBase.cs index b57b8e9780e..10c343f9256 100644 --- a/src/Nest/Domain/Aggregations/BucketAggregationBase.cs +++ b/src/Nest/Domain/Aggregations/BucketAggregationBase.cs @@ -1,7 +1,9 @@ -namespace Nest +using System.Collections.Generic; +namespace Nest { public abstract class BucketAggregationBase : AggregationsHelper , IBucketAggregation - { - + { + protected BucketAggregationBase() { } + protected BucketAggregationBase(IDictionary aggregations) : base(aggregations) { } } } \ No newline at end of file diff --git a/src/Nest/Domain/Aggregations/SingleBucket.cs b/src/Nest/Domain/Aggregations/SingleBucket.cs index 9cace750310..5e3e0e66b88 100644 --- a/src/Nest/Domain/Aggregations/SingleBucket.cs +++ b/src/Nest/Domain/Aggregations/SingleBucket.cs @@ -1,9 +1,14 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; +using System.Collections.Generic; namespace Nest { public class SingleBucket : BucketAggregationBase - { + { + public SingleBucket() { } + + public SingleBucket(IDictionary aggregations) : base(aggregations) { } + [JsonProperty("doc_count")] public long DocCount { get; set; } } diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index 6ed4b35933b..5985c814371 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -418,6 +418,7 @@ + diff --git a/src/Tests/Nest.Tests.Unit/Search/Aggregations/SingleBucketAggregationTests.cs b/src/Tests/Nest.Tests.Unit/Search/Aggregations/SingleBucketAggregationTests.cs new file mode 100644 index 00000000000..d14a40917fd --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Search/Aggregations/SingleBucketAggregationTests.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using FluentAssertions; + +namespace Nest.Tests.Unit.Search.Aggregations +{ + [TestFixture] + public class SingleBucketAggregationTests + { + [Test] + public void CanSetInnerAggregationsInConstructor() + { + var bucket = new SingleBucket(new Dictionary { + {"some_agg", new KeyItem { Key = "agg_key", DocCount = 123 }} + }); + + bucket.Aggregations.Should().ContainKey("some_agg"); + + var item = (KeyItem) bucket.Aggregations["some_agg"]; + item.DocCount.Should().Be(123); + item.Key.Should().Be("agg_key"); + + } + } +}