Permalink
Browse files

Merge pull request #2 from lshift/253

Merged 253 into master
  • Loading branch information...
0x6e6562 committed Jun 28, 2011
2 parents 4a8340a + 807d794 commit e5c8caf5a0144deb6adf0be64a6b21a9ee8e4567
Showing with 1,569 additions and 77 deletions.
  1. +152 −0 DiffaParticipant/Net.LShift.Diffa.Participants.Test/AggregationBuilderTest.cs
  2. +335 −0 DiffaParticipant/Net.LShift.Diffa.Participants.Test/BaseScanningParticipantTest.cs
  3. +178 −0 DiffaParticipant/Net.LShift.Diffa.Participants.Test/ConstraintsBuilderTest.cs
  4. +3 −3 DiffaParticipant/Net.LShift.Diffa.Participants.Test/DateCategoryFunctionTest.cs
  5. +3 −3 DiffaParticipant/Net.LShift.Diffa.Participants.Test/IntegerCategoryFunctionTest.cs
  6. +7 −0 DiffaParticipant/Net.LShift.Diffa.Participants.Test/Net.LShift.Diffa.Participants.Test.csproj
  7. +41 −0 DiffaParticipant/Net.LShift.Diffa.Participants.Test/PrefixCategoryFunctionTest.cs
  8. +53 −0 DiffaParticipant/Net.LShift.Diffa.Participants.Test/PrefixQueryConstraintTest.cs
  9. +120 −0 DiffaParticipant/Net.LShift.Diffa.Participants/AggregationBuilder.cs
  10. +32 −0 DiffaParticipant/Net.LShift.Diffa.Participants/BaseCategoryFunction.cs
  11. +87 −0 DiffaParticipant/Net.LShift.Diffa.Participants/BaseScanningParticipant.cs
  12. +6 −3 DiffaParticipant/Net.LShift.Diffa.Participants/ByNameCategoryFunction.cs
  13. +115 −0 DiffaParticipant/Net.LShift.Diffa.Participants/ConstraintsBuilder.cs
  14. +16 −3 DiffaParticipant/Net.LShift.Diffa.Participants/DateCategoryFunction.cs
  15. +109 −61 DiffaParticipant/Net.LShift.Diffa.Participants/DigestBuilder.cs
  16. +8 −0 DiffaParticipant/Net.LShift.Diffa.Participants/ICategoryFunction.cs
  17. +68 −0 DiffaParticipant/Net.LShift.Diffa.Participants/IQueryConstraint.cs
  18. +36 −0 DiffaParticipant/Net.LShift.Diffa.Participants/IScanningParticipantContract.cs
  19. +6 −4 DiffaParticipant/Net.LShift.Diffa.Participants/IntegerCategoryFunction.cs
  20. +23 −0 DiffaParticipant/Net.LShift.Diffa.Participants/InvalidConstraintException.cs
  21. +24 −0 DiffaParticipant/Net.LShift.Diffa.Participants/InvalidGranularityException.cs
  22. +31 −0 DiffaParticipant/Net.LShift.Diffa.Participants/InvalidScanRequestException.cs
  23. +12 −0 DiffaParticipant/Net.LShift.Diffa.Participants/Net.LShift.Diffa.Participants.csproj
  24. +39 −0 DiffaParticipant/Net.LShift.Diffa.Participants/PrefixCategoryFunction.cs
  25. +65 −0 DiffaParticipant/Net.LShift.Diffa.Participants/ScanResultEntry.cs
@@ -0,0 +1,152 @@
+//
+// Copyright (C) 2011 LShift Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace Net.LShift.Diffa.Participants.Test {
+ [TestFixture]
+ public class AggregationBuilderTest {
+ [Test]
+ public void ShouldNotAddDateAggregationForEmptyRequest() {
+ var req = new NameValueCollection();
+ var builder = new AggregationBuilder(req);
+
+ builder.MaybeAddDateAggregation("test");
+ Assert.AreEqual(0, builder.ToList().Count);
+ }
+
+ [Test]
+ public void ShouldAddDateAggregationWhenParameterIsAvailable() {
+ var req = new NameValueCollection();
+ req.Add("bizDate-granularity", "monthly");
+ var builder = new AggregationBuilder(req);
+
+ builder.MaybeAddDateAggregation("bizDate");
+ Assert.AreEqual(1, builder.ToList().Count);
+ Assert.That(builder.ToList()[0], Is.InstanceOf(typeof(DateCategoryFunction)));
+ }
+
+ [Test]
+ public void ShouldNotAddDateAggregationWhenDifferentParameterIsAvailable() {
+ var req = new NameValueCollection();
+ req.Add("someString-granularity", "prefix(1)");
+ var builder = new AggregationBuilder(req);
+
+ builder.MaybeAddDateAggregation("bizDate");
+ Assert.AreEqual(0, builder.ToList().Count);
+ }
+
+ [Test]
+ public void ShouldNotAddNyNameAggregationForEmptyRequest() {
+ var req = new NameValueCollection();
+ var builder = new AggregationBuilder(req);
+
+ builder.MaybeAddByNameAggregation("test");
+ Assert.AreEqual(0, builder.ToList().Count);
+ }
+
+ [Test]
+ public void ShouldAddByNameAggregationWhenParameterIsAvailable() {
+ var req = new NameValueCollection();
+ req.Add("someString-granularity", "by-name");
+ var builder = new AggregationBuilder(req);
+
+ builder.MaybeAddByNameAggregation("someString");
+ Assert.AreEqual(1, builder.ToList().Count);
+ Assert.That(builder.ToList()[0], Is.InstanceOf(typeof(ByNameCategoryFunction)));
+ }
+
+ [Test]
+ public void ShouldInvalidGranularityExceptionWhenGranularityValueIsBad() {
+ var req = new NameValueCollection();
+ req.Add("bizDate-granularity", "invalid");
+ var builder = new AggregationBuilder(req);
+
+ try {
+ builder.MaybeAddDateAggregation("bizDate");
+ Assert.Fail("Should have thrown InvalidGranularityException");
+ } catch (InvalidGranularityException ex) {
+ Assert.AreEqual("The aggregation value 'invalid' is not valid for the field 'bizDate'", ex.Message);
+ }
+ }
+
+ [Test]
+ 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);
+ }
+
+ [Test]
+ 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);
+ }
+ }
+
+ [Test]
+ 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);
+ }
+ }
+
+ [Test]
+ 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);
+ }
+
+ [Test]
+ 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);
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit e5c8caf

Please sign in to comment.