public void ShouldAddPrefixAggregationWhenParameterIsAvailable() { var req = new NameValueCollection { { "someString-length", "5" } }; var builder = new AggregationBuilder(req); builder.MaybeAddPrefixAggregation("someString"); Assert.AreEqual(1, builder.ToList().Count); Assert.That(builder.ToList()[0], Is.InstanceOf(typeof(PrefixCategoryFunction))); Assert.AreEqual(5, ((PrefixCategoryFunction)builder.ToList()[0]).Length); }
public void ShouldThrowInvalidGranularityExceptionWhenPrefixLengthIsntANumber() { var req = new NameValueCollection { { "someString-length", "blah" } }; var builder = new AggregationBuilder(req); try { builder.MaybeAddPrefixAggregation("someString"); Assert.Fail("Should have thrown InvalidGranularityException"); } catch (InvalidGranularityException ex) { Assert.AreEqual("The aggregation value 'blah' is not valid for the field 'someString'", ex.Message); } }