protected override IEnumerable <IQueryConstraint> DetermineConstraints(System.Collections.Specialized.NameValueCollection requestParams) { var builder = new ConstraintsBuilder(requestParams); builder.MaybeAddDateRangeConstraint("bizDate"); builder.MaybeAddSetConstraint("bookId"); return(builder.ToList()); }
public void ShouldNotAddSetConstraintForEmptyRequest() { var req = new NameValueCollection(); var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("test"); Assert.AreEqual(0, builder.ToList().Count); }
public void ShouldAddSetConstraintWhenMultipleValuesArePresent() { var req = new NameValueCollection {{"someString", "a"}, {"someString", "b"}, {"someString", "c"}}; var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("someString"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof (SetQueryConstraint), builder.ToList()[0]); var c = (SetQueryConstraint) builder.ToList()[0]; var expected = new HashSet<String> { "a", "b", "c" }; Assert.That(expected, Is.EqualTo(c.Values).AsCollection); }
public void ShouldAddSetConstraintWhenMultipleValuesArePresent() { var req = new NameValueCollection { { "someString", "a" }, { "someString", "b" }, { "someString", "c" } }; var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("someString"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof(SetQueryConstraint), builder.ToList()[0]); var c = (SetQueryConstraint)builder.ToList()[0]; var expected = new HashSet <String> { "a", "b", "c" }; Assert.That(expected, Is.EqualTo(c.Values).AsCollection); }
public void ShouldAddSetConstraintWhenSingleValueIsPresent() { var req = new NameValueCollection(); req["someString"] = "a"; var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("someString"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof(SetQueryConstraint), builder.ToList()[0]); var c = (SetQueryConstraint)builder.ToList()[0]; var expected = new HashSet <String> { "a" }; Assert.AreEqual(expected, c.Values); }
public void ShouldBeAbleToAddBothSetAndDateConstraints() { var req = new NameValueCollection { { "someString", "a" }, { "bizDate-start", "2011-06-01" }, { "bizDate-end", "2011-06-30" } }; var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("someString"); builder.MaybeAddDateRangeConstraint("bizDate"); Assert.AreEqual(2, builder.ToList().Count); Assert.IsInstanceOf(typeof(SetQueryConstraint), builder.ToList()[0]); var sc = (SetQueryConstraint)builder.ToList()[0]; Assert.That(new HashSet <String> { "a" }, Is.EqualTo(sc.Values).AsCollection); Assert.IsInstanceOf(typeof(DateRangeQueryConstraint), builder.ToList()[1]); var c = (DateRangeQueryConstraint)builder.ToList()[1]; Assert.That(new DateTime(2011, 6, 1), Is.EqualTo(c.LowerBound.Value)); Assert.That(new DateTime(2011, 6, 30), Is.EqualTo(c.UpperBound.Value)); }
protected override IEnumerable<IQueryConstraint> DetermineConstraints(System.Collections.Specialized.NameValueCollection requestParams) { var builder = new ConstraintsBuilder(requestParams); builder.MaybeAddDateRangeConstraint("bizDate"); builder.MaybeAddSetConstraint("bookId"); return builder.ToList(); }
public void ShouldAddSetConstraintWhenSingleValueIsPresent() { var req = new NameValueCollection(); req["someString"] = "a"; var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("someString"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof (SetQueryConstraint), builder.ToList()[0]); var c = (SetQueryConstraint) builder.ToList()[0]; var expected = new HashSet<String> {"a"}; Assert.AreEqual(expected, c.Values); }
public void ShouldNotAddSetConstraintForEmptyRequest() { var req = new NameValueCollection(); var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("test"); Assert.AreEqual(0, builder.ToList().Count); }
public void ShouldBeAbleToAddBothSetAndDateConstraints() { var req = new NameValueCollection { { "someString", "a" }, { "bizDate-start", "2011-06-01" }, { "bizDate-end", "2011-06-30" } }; var builder = new ConstraintsBuilder(req); builder.MaybeAddSetConstraint("someString"); builder.MaybeAddDateRangeConstraint("bizDate"); Assert.AreEqual(2, builder.ToList().Count); Assert.IsInstanceOf(typeof(SetQueryConstraint), builder.ToList()[0]); var sc = (SetQueryConstraint)builder.ToList()[0]; Assert.That(new HashSet<String> { "a" }, Is.EqualTo(sc.Values).AsCollection); Assert.IsInstanceOf(typeof(DateRangeQueryConstraint), builder.ToList()[1]); var c = (DateRangeQueryConstraint)builder.ToList()[1]; Assert.That(new DateTime(2011, 6, 1), Is.EqualTo(c.LowerBound.Value)); Assert.That(new DateTime(2011, 6, 30), Is.EqualTo(c.UpperBound.Value)); }