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 ShouldAddPrefixConstraintWhenValueIsPresent() { var req = new NameValueCollection(); req["someString-prefix"] = "abc"; var builder = new ConstraintsBuilder(req); builder.MaybeAddPrefixConstraint("someString"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof(PrefixQueryConstraint), builder.ToList()[0]); var c = (PrefixQueryConstraint)builder.ToList()[0]; Assert.AreEqual("abc", c.Prefix); }
public void ShouldAddDateRangeConstraintWhenBothStartAndEndArePresent() { var req = new NameValueCollection(); req["bizDate-start"] = "2011-06-01"; req["bizDate-end"] = "2011-06-30"; var builder = new ConstraintsBuilder(req); builder.MaybeAddDateRangeConstraint("bizDate"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof (DateRangeQueryConstraint), builder.ToList()[0]); var c = (DateRangeQueryConstraint) builder.ToList()[0]; Assert.AreEqual(new DateTime(2011, 6, 1), c.LowerBound); Assert.AreEqual(new DateTime(2011, 6, 30), c.UpperBound); Assert.AreEqual("bizDate", c.Category); }
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 ShouldAddTimeRangeConstraintWhenBothStartAndEndArePresent() { var req = new NameValueCollection(); req["createTime-start"] = "2011-06-06T12:00:00.000Z"; req["createTime-end"] = "2011-06-06T16:00:00.000Z"; var builder = new ConstraintsBuilder(req); builder.MaybeAddTimeRangeConstraint("createTime"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof(DateRangeQueryConstraint), builder.ToList()[0]); var c = (DateRangeQueryConstraint)builder.ToList()[0]; Assert.AreEqual(new DateTime(2011, 6, 6, 12, 0, 0, 0, DateTimeKind.Utc), c.LowerBound); Assert.AreEqual(new DateTime(2011, 6, 6, 16, 0, 0, 0, DateTimeKind.Utc), c.UpperBound); }
public void ShouldAddDateRangeConstraintWhenBothStartAndEndArePresent() { var req = new NameValueCollection(); req["bizDate-start"] = "2011-06-01"; req["bizDate-end"] = "2011-06-30"; var builder = new ConstraintsBuilder(req); builder.MaybeAddDateRangeConstraint("bizDate"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof(DateRangeQueryConstraint), builder.ToList()[0]); var c = (DateRangeQueryConstraint)builder.ToList()[0]; Assert.AreEqual(new DateTime(2011, 6, 1), c.LowerBound); Assert.AreEqual(new DateTime(2011, 6, 30), c.UpperBound); Assert.AreEqual("bizDate", c.Category); }
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 ShouldAddTimeRangeConstraintWhenBothStartAndEndArePresent() { var req = new NameValueCollection(); req["createTime-start"] = "2011-06-06T12:00:00.000Z"; req["createTime-end"] = "2011-06-06T16:00:00.000Z"; var builder = new ConstraintsBuilder(req); builder.MaybeAddTimeRangeConstraint("createTime"); Assert.AreEqual(1, builder.ToList().Count); Assert.IsInstanceOf(typeof (DateRangeQueryConstraint), builder.ToList()[0]); var c = (DateRangeQueryConstraint) builder.ToList()[0]; Assert.AreEqual(new DateTime(2011, 6, 6, 12, 0, 0, 0, DateTimeKind.Utc), c.LowerBound); Assert.AreEqual(new DateTime(2011, 6, 6, 16, 0, 0, 0, DateTimeKind.Utc), c.UpperBound); }
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 ShouldNotAddTimeRangeConstraintForEmptyRequest() { var req = new NameValueCollection(); var builder = new ConstraintsBuilder(req); builder.MaybeAddTimeRangeConstraint("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)); }