public void OrderBy_Duplicate_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new OrderByClause
            {
                Orderings =
                {
                    new Ordering(GetExpression((Contact c) => c.FirstName), OrderingDirection.Asc)
                }
            });
            builder.AddClause(new OrderByClause
            {
                Orderings =
                {
                    new Ordering(GetExpression((Contact c) => c.LastName), OrderingDirection.Desc)
                }
            });
            builder.AddClause(new SelectClause(Expression.Constant(null)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.OrderBy, Is.EqualTo("LastName desc,FirstName asc"));
        }
Beispiel #2
0
        /// <summary>
        /// Generate a function with no arguments that returns an int given that name. The
        /// actual statement is a very simple constant.
        /// </summary>
        /// <param name="fname"></param>
        /// <returns></returns>
        public static QMFuncSource GenerateFunction()
        {
            int[] ints = new int[10];
            var   qmb  = new QueryModelBuilder();

            qmb.AddClause(new MainFromClause("i", typeof(int), Expression.Constant(ints)));
            qmb.AddClause(new SelectClause(Expression.Constant(1)));
            qmb.AddResultOperator(new Remotion.Linq.Clauses.ResultOperators.CountResultOperator());

            var h = new QMFuncHeader()
            {
                Arguments = new object[] { }, QM = qmb.Build()
            };

            h.QMText = h.QM.ToString();
            var f = new QMFuncSource(h);

            var p           = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var st          = new StatementAssign(p, new ValSimple("5", typeof(int)));
            var inlineblock = new StatementInlineBlock();

            inlineblock.Add(st);
            inlineblock.Add(new StatementReturn(p));
            f.SetCodeBody(inlineblock);

            return(f);
        }
        public void Select_Nested_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(GetExpression((Contact c) => c.Address.PostalCode)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Select, Is.EqualTo("Address/PostalCode"));
        }
Beispiel #4
0
        private static QueryModelBuilder CreateQueryBuilder <T>(bool attachSelect)
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(T), Expression.Constant(null)));

            if (attachSelect)
            {
                builder.AddClause(new SelectClause(new QuerySourceReferenceExpression(builder.MainFromClause)));
            }

            return(builder);
        }
        public void Select_Complex_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(GetExpression((Contact c) => c.Civility.ToString().Length)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Select, Is.EqualTo("Civility"));
        }
        public void MainType_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(Expression.Constant(null)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.MainType, Is.EqualTo(typeof(Contact)));
        }
        public void Select_Array_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(GetExpression((Contact c) => new[] { c.FirstName, c.LastName })));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Select, Is.EqualTo("FirstName,LastName"));
        }
        public void ResultOperator_Skip_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(Expression.Constant(null)));
            builder.AddResultOperator(new SkipResultOperator(Expression.Constant(10)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.StartIndex, Is.EqualTo(11));
        }
        public void Select_ProtocolProperty_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(GetExpression((Contact c) => c.Key)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Select, Is.Null);
            Assert.That(visitor.Precedence, Is.EqualTo(0));
        }
        public void ResultOperator_Fetch_Permissions_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(Expression.Constant(null)));
            builder.AddResultOperator(new FetchResultOperator(GetExpression((Contact c) => c.Permissions)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Include, Is.EqualTo("$permissions"));
        }
        public void ResultOperator_WithPrecedence_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(new QuerySourceReferenceExpression(builder.MainFromClause)));
            builder.AddResultOperator(new WithPrecedenceResultOperator(3));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Precedence, Is.EqualTo(3));
        }
        public void Where_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new WhereClause(GetExpression((Contact c) => c.Active)));
            builder.AddClause(new SelectClause(Expression.Constant(null)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Where, Is.EqualTo("Active"));
        }
        public void ResultOperator_Take_Multiple_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(Expression.Constant(null)));
            builder.AddResultOperator(new TakeResultOperator(Expression.Constant(10)));
            builder.AddResultOperator(new TakeResultOperator(Expression.Constant(5)));
            builder.AddResultOperator(new TakeResultOperator(Expression.Constant(8)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Count, Is.EqualTo(5));
        }
        public void ResultOperator_WithExtensionArg_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new SelectClause(Expression.Constant(null)));
            builder.AddResultOperator(new WithExtensionArgResultOperator("foo", "bar"));
            builder.AddResultOperator(new WithExtensionArgResultOperator("hello", "world"));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.ExtensionArgs, Is.EqualTo(new Dictionary <string, string> {
                { "foo", "bar" }, { "hello", "world" }
            }));
        }
Beispiel #15
0
        public void TypeOfSequence()
        {
            var qmb = new QueryModelBuilder();

            qmb.AddClause(new SelectClause(Expression.Constant(1.0)));
            int[] list = new int[10];
            qmb.AddClause(new MainFromClause("r1", typeof(int), Expression.Constant(list)));

            var h = new QMFuncHeader()
            {
                Arguments = new object[] { }, IsSequence = true, QM = qmb.Build(), QMText = "hi"
            };
            var src = new QMFuncSource(h);

            Assert.AreEqual(typeof(double[]), src.ResultType, "result type");

            Assert.AreEqual(typeof(double[]), src.CacheVariable.Type, "Type of cache");
            Assert.AreEqual(typeof(bool), src.CacheVariableGood.Type, "Type of the cache good flag");
        }
        public void OrderBy_ProtocolProperty_Test()
        {
            var builder = new QueryModelBuilder();

            builder.AddClause(new MainFromClause("x", typeof(Contact), Expression.Constant(null)));
            builder.AddClause(new OrderByClause
            {
                Orderings =
                {
                    new Ordering(GetExpression((Contact c) => c.Key), OrderingDirection.Asc)
                }
            });
            builder.AddClause(new SelectClause(Expression.Constant(null)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.OrderBy, Is.EqualTo("$key asc"));
        }
Beispiel #17
0
        public void AddClause_BodyClause()
        {
            _builder.AddClause(_whereClause1);

            Assert.That(_builder.BodyClauses, Is.EqualTo(new[] { _whereClause1 }));
        }