public void ResultOperator_Fetch_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 FetchResultOperator(GetExpression((Contact c) => c.Address)));
            builder.AddResultOperator(new FetchResultOperator(GetExpression((Contact c) => c.Address.Street)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.Include, Is.EqualTo("Address,Address/Street"));
        }
        public void ResultOperator_Take_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 TakeResultOperator(Expression.Constant(10)));
            builder.AddResultOperator(new SkipResultOperator(Expression.Constant(3)));

            var visitor = new SDataQueryModelVisitor();

            visitor.VisitQueryModel(builder.Build());

            Assert.That(visitor.StartIndex, Is.EqualTo(4));
            Assert.That(visitor.Count, Is.EqualTo(7));
        }
예제 #3
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 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" }
            }));
        }
        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));
        }
예제 #6
0
        public void TypeOfNonSequence()
        {
            var qmb = new QueryModelBuilder();

            qmb.AddClause(new SelectClause(Expression.Constant(1.0)));
            qmb.AddResultOperator(new Remotion.Linq.Clauses.ResultOperators.FirstResultOperator(true));
            int[] list = new int[10];
            qmb.AddClause(new MainFromClause("r1", typeof(int), Expression.Constant(list)));

            var h = new QMFuncHeader()
            {
                Arguments = new object[] { }, IsSequence = false, 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");
        }
예제 #7
0
 public void AddResultOperator()
 {
     _builder.AddResultOperator(_resultOperator1);
     Assert.That(_builder.ResultOperators, Has.Member(_resultOperator1));
 }