Example #1
0
        public void OperationTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue.Op(AValue <Dummy> .Field(x => x.Baz), "/", AValue <Dummy> .Field(x => x.Bar)));

            Assert.AreEqual("LET x = (x.Baz / x.Bar)", query.GetExpression());
        }
Example #2
0
        public void ForTest()
        {
            AQuery query = _db.Query
                           .For("x", AValue.Field(TestDocumentCollectionName));

            Assert.AreEqual("FOR x IN " + TestDocumentCollectionName, query.GetExpression());
        }
Example #3
0
        public void AttributesTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue.Attributes(AValue <Dummy> .Field(x => x.Foo)));

            Assert.AreEqual("LET x = ATTRIBUTES(x.Foo)", query.GetExpression());
        }
Example #4
0
        public void SortTest()
        {
            AQuery query = _db.Query
                           .Sort(AValue <Dummy> .Field(x => x.Foo), AqlSort.Direction.Desc);

            Assert.AreEqual("SORT x.Foo DESC", query.GetExpression());
        }
Example #5
0
        public void FieldSuffixTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue <Dummy> .Field <int>(x => x.Foo, ".was"));

            Assert.AreEqual("LET x = x.Foo.was", query.GetExpression());
        }
Example #6
0
        public void FieldTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue <Dummy> .Field(x => x.Bar));

            Assert.AreEqual("LET x = x.Bar", query.GetExpression());
        }
Example #7
0
        public void ObjectTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue <Dummy> .Object(
                                    (
                                        x => x.Id,
                                        AValue.Bind("asdf")
                                    ),
                                    (
                                        x => x.Foo,
                                        AValue <Dummy> .Field(z => z.Foo)
                                    ),
                                    (
                                        x => x.Bar,
                                        AValue.Bind(10)
                                    ),
                                    (
                                        x => x.Baz,
                                        AValue <Dummy> .Field(x => x.Bar)
                                    )
                                    ));

            Assert.AreEqual("LET x = {\"_id\":@var0,\"Foo\":z.Foo,\"Bar\":@var1,\"Baz\":x.Bar}", query.GetExpression());
            Assert.AreEqual(typeof(string), query.GetBindedVars()[0].GetType());
            Assert.AreEqual(typeof(int), query.GetBindedVars()[1].GetType());
        }
Example #8
0
        public void BetweenTest()
        {
            AQuery query = _db.Query.Filter(AFilter.Between(AValue <Dummy> .Field(x => x.Bar), AValue.Bind(1), AValue.Bind(50)));

            Assert.AreEqual("FILTER (x.Bar >= @var0 AND x.Bar <= @var1)", query.GetExpression());
            Assert.AreEqual(1, query.GetBindedVars()[0]);
            Assert.AreEqual(50, query.GetBindedVars()[1]);
        }
Example #9
0
        public void SimpleTest()
        {
            //AQuery query = _db.Query.Filter(FilterBuilder<Dummy>.Eq( x => x.Foo, "asd"));
            AQuery query = _db.Query.Filter(AFilter.Eq(AValue <Dummy> .Field(x => x.Foo), AValue.Bind("asd")));

            Assert.AreEqual("FILTER x.Foo == @var0", query.GetExpression());
            Assert.AreEqual("asd", query.GetBindedVars()[0]);
        }
Example #10
0
        public void InTest()
        {
            //AQuery query = _db.Query.Filter(FilterBuilder<Dummy>.In(x => x.Foo, new[] {"asd", "qwe"}));
            AQuery query = _db.Query.Filter(AFilter.In(AValue <Dummy> .Field(x => x.Foo), AValueArray.Bind("asd", "qwe")));

            Assert.AreEqual("FILTER x.Foo IN [@var0,@var1]", query.GetExpression());
            Assert.AreEqual("asd", query.GetBindedVars()[0]);
            Assert.AreEqual("qwe", query.GetBindedVars()[1]);
        }
Example #11
0
        public void TypeTest()
        {
            Type dummyType = typeof(Dummy);

            //AQuery query = _db.Query.Filter(FilterBuilder<Dummy>.Eq(x => x.GetType(), dummyType));
            AQuery query = _db.Query.Filter(AFilter.Eq(AValue <Dummy> .Field(x => x.GetType()), AValue.Bind(dummyType)));

            Assert.AreEqual("FILTER x.$type == @var0", query.GetExpression());
            Assert.AreEqual(dummyType.FullName + ", " + dummyType.Assembly.GetName().Name, query.GetBindedVars()[0]);
        }
Example #12
0
        public void MultipleTest()
        {
            AQuery query = _db.Query
                           //.Filter(FilterBuilder<Dummy>.Lt(x => x.Baz, 50))
                           //.Filter(FilterBuilder<Dummy>.Gte(x => x.Bar, 1));
                           .Filter(AFilter.Lt(AValue <Dummy> .Field(x => x.Baz), AValue.Bind(50)))
                           .Filter(AFilter.Gte(AValue <Dummy> .Field(x => x.Bar), AValue.Bind(1)));

            Assert.AreEqual("FILTER x.Baz < @var0 FILTER x.Bar >= @var1", query.GetExpression());
            Assert.AreEqual(50, query.GetBindedVars()[0]);
            Assert.AreEqual(1, query.GetBindedVars()[1]);
        }
Example #13
0
        public void IfTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue.If(
                                    AFilter.Eq(AValue <Dummy> .Field(x => x.Bar), AValue.Bind(2)),
                                    AValue <Dummy> .Field(x => x.Baz),
                                    AValue.Bind(0)
                                    ));

            Assert.AreEqual("LET x = (x.Bar == @var0 ? x.Baz : @var1)", query.GetExpression());
            Assert.AreEqual(2, query.GetBindedVars()[0]);
            Assert.AreEqual(0, query.GetBindedVars()[1]);
        }
Example #14
0
        public void OrTest()
        {
            AQuery query = _db.Query.Filter(
                AFilter.Or(
                    AFilter.Eq(AValue <Dummy> .Field(x => x.Foo), AValue.Bind("asd")),
                    AFilter.Gt(AValue <Dummy> .Field(x => x.Bar), AValue.Bind(1))
                    )
                );

            Assert.AreEqual("FILTER (x.Foo == @var0 OR x.Bar > @var1)", query.GetExpression());
            Assert.AreEqual("asd", query.GetBindedVars()[0]);
            Assert.AreEqual(1, query.GetBindedVars()[1]);
        }
Example #15
0
        public void LetSubQueryTest()
        {
            AQuery subquery = _db.Query
                              .For("y", AValue.Field(TestDocumentCollectionName))
                              .Collect()
                              .Aggregate("max", ANumeric.Max(AValue.Field("y.value")))
                              .Return(AReturn.Variable("max"));

            AQuery query = _db.Query
                           .Let("x", AValue.Subquery <int>(subquery));

            Assert.AreEqual("LET x = (FOR y IN " + TestDocumentCollectionName + " COLLECT AGGREGATE max = MAX(y.value) RETURN max)", query.GetExpression());
        }
Example #16
0
        public void ObjectDynamicTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue.Object(
                                    (
                                        "_id",
                                        AValue.Bind("asdf")
                                    ),
                                    (
                                        "Foo",
                                        AValue <Dummy> .Field(z => z.Foo)
                                    ),
                                    (
                                        "lalalal",
                                        AValue.Bind(10)
                                    )
                                    ));

            Assert.AreEqual("LET x = {\"_id\":@var0,\"Foo\":z.Foo,\"lalalal\":@var1}", query.GetExpression());
            Assert.AreEqual(typeof(string), query.GetBindedVars()[0].GetType());
            Assert.AreEqual(typeof(int), query.GetBindedVars()[1].GetType());
        }
Example #17
0
        public void LetTest()
        {
            AQuery query = _db.Query
                           .Let("x", AValue.Document <Dummy>(TestDocumentCollectionName, AValue.Field <string>("asd")));

            Assert.AreEqual("LET x = DOCUMENT('" + TestDocumentCollectionName + "',asd)", query.GetExpression());
        }