public void ShouldAddIntegerAggregationWhenParameterIsAvailable() { var req = new NameValueCollection { { "someInt-granularity", "100s" } }; var builder = new AggregationBuilder(req); builder.MaybeAddIntegerAggregation("someInt"); Assert.AreEqual(1, builder.ToList().Count); Assert.That(builder.ToList()[0], Is.InstanceOf(typeof(IntegerCategoryFunction))); Assert.AreEqual(100, ((IntegerCategoryFunction)builder.ToList()[0]).Denominator); }
public void ShouldThrowInvalidGranularityExceptionWhenBadNumberedIntegerGranularityIsGiven() { var req = new NameValueCollection { { "someInt-granularity", "10a0s" } }; var builder = new AggregationBuilder(req); try { builder.MaybeAddIntegerAggregation("someInt"); Assert.Fail("Should have thrown InvalidGranularityException"); } catch (InvalidGranularityException ex) { Assert.AreEqual("The aggregation value '10a0s' is not valid for the field 'someInt'", ex.Message); } }
public void ShouldThrowInvalidGranularityExceptionWhenCompletelyInvalidIntegerGranularityIsGiven() { var req = new NameValueCollection { { "someInt-granularity", "blah" } }; var builder = new AggregationBuilder(req); try { builder.MaybeAddIntegerAggregation("someInt"); Assert.Fail("Should have thrown InvalidGranularityException"); } catch (InvalidGranularityException ex) { Assert.AreEqual("The aggregation value 'blah' is not valid for the field 'someInt'", ex.Message); } }