Ejemplo n.º 1
0
 public void TestLoopVarSetting()
 {
     var c = new CodeContext();
     var v = Expression.Variable(typeof(int), "d");
     c.SetLoopVariable(v, null);
     Assert.AreEqual(v, c.LoopVariable, "set didn't work");
 }
Ejemplo n.º 2
0
 public void TestSetExpressionAndPop()
 {
     var c = new CodeContext();
     Assert.IsNull(c.GetReplacement("d"), "initally get");
     var myvar = Expression.Variable(typeof(int), "fork");
     var p = c.Add("d", myvar);
     Assert.AreEqual(myvar, c.GetReplacement("d"), "callback after store");
     p.Pop();
     Assert.IsNull(c.GetReplacement("d"), "Final get");
 }
Ejemplo n.º 3
0
        public void TestRemoveAndPopRemove()
        {
            var c = new CodeContext();
            var myvar = Expression.Variable(typeof(int), "d");
            c.Add("dude", myvar);

            var popper = c.Remove("dude");
            Assert.IsNull(c.GetReplacement("dude"), "incorrect dummy name");
            popper.Pop();
            Assert.AreEqual("d", (c.GetReplacement("dude") as ParameterExpression).Name, "incorrect dummy name");
        }
Ejemplo n.º 4
0
        public void TestExpressionHiding()
        {
            var c = new CodeContext();
            var myvar1 = Expression.Variable(typeof(int), "d");
            var myvar2 = Expression.Variable(typeof(float), "dude");

            c.Add("p", myvar1);
            var p = c.Add("p", myvar2);
            Assert.AreEqual(myvar2, c.GetReplacement("p"), "replacement check");
            p.Pop();
            Assert.AreEqual(myvar1, c.GetReplacement("p"), "poped state");
        }
Ejemplo n.º 5
0
 internal Expression ProcessResultOperator(
     [PexAssumeUnderTest]ROCount target,
     CountResultOperator resultOperator,
     QueryModel queryModel,
     GeneratedCode codeEnv
 )
 {
     int origCount = 0;
     if (codeEnv != null)
         origCount = codeEnv.CodeBody.Statements.Count();
     CodeContext c = new CodeContext();
     Expression result = target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, null);
     Assert.AreEqual(origCount + 1, codeEnv.CodeBody.Statements.Count(), "Expected an added statement!");
     Assert.IsInstanceOfType(codeEnv.CodeBody.Statements.Last(), typeof(StatementAggregate), "Statement to inc the integer must have been done!");
     Assert.AreEqual(result.Type, typeof(int), "Expected to be calculating an integer");
     return result;
 }
Ejemplo n.º 6
0
 public void TestLoopVarSetNull()
 {
     var c = new CodeContext();
     c.SetLoopVariable(null, null);
 }
Ejemplo n.º 7
0
 public void TestRemoveOfNothing()
 {
     var c = new CodeContext();
     var popper = c.Remove("dude");
     popper.Pop();
 }
Ejemplo n.º 8
0
 public CCReplacementExpression(CodeContext codeContext, string varName, Expression iValue)
 {
     _context = codeContext;
     _varName = varName;
     _oldVal = iValue;
 }
Ejemplo n.º 9
0
        public void TestAddQueryRefereceSource()
        {
            var c = new CodeContext();
            var qs = new DummyQueryReference();
            var v = Expression.Constant(10);
            c.Add(qs, v);

            Assert.AreEqual(v, c.GetReplacement(qs), "Query Source Lookup.");
        }
Ejemplo n.º 10
0
        public void TestPopReplaceQM()
        {
            var c = new CodeContext();
            var qm = new QueryModel(new Remotion.Linq.Clauses.MainFromClause("dude", typeof(int), Expression.Parameter(typeof(IEnumerable<int>))),
                new Remotion.Linq.Clauses.SelectClause(Expression.Parameter(typeof(int))));

            var e1 = Expression.Parameter(typeof(int));
            var s1 = c.Add(qm, e1);
            Assert.AreEqual(e1, c.GetReplacement(qm), "bad lookup");
            var e2 = Expression.Parameter(typeof(int));
            var s2 = c.Add(qm, e2);

            Assert.AreEqual(e2, c.GetReplacement(qm), "high level lookup");
            s2.Pop();
            Assert.AreEqual(e1, c.GetReplacement(qm), "second level lookup");
        }
Ejemplo n.º 11
0
 public void TestLoopVarCTor()
 {
     var c = new CodeContext();
     Assert.IsNull(c.LoopVariable, "ctor isn't null");
 }
Ejemplo n.º 12
0
        public void TestPopQM()
        {
            var c = new CodeContext();
            var qm = new QueryModel(new Remotion.Linq.Clauses.MainFromClause("dude", typeof(int), Expression.Parameter(typeof(IEnumerable<int>))),
                new Remotion.Linq.Clauses.SelectClause(Expression.Parameter(typeof(int))));

            Assert.IsNull(c.GetReplacement(qm), "should not be there yet");

            var e = Expression.Parameter(typeof(int));
            var s = c.Add(qm, e);
            Assert.AreEqual(e, c.GetReplacement(qm), "bad lookup");

            s.Pop();
            Assert.IsNull(c.GetReplacement(qm), "should be gone now.");
        }
Ejemplo n.º 13
0
        public void TestQSReloadLookup()
        {
            var c = new CodeContext();
            var qs1 = new DummyQueryReference();
            var qs2 = new DummyQueryReference();
            var qsList = new IQuerySource[] { qs1, qs2 };

            c.RestoreQuerySourceLookups(qsList);
            Assert.AreEqual(2, c.GetAndResetQuerySourceLookups().Length, "# after a restore");
        }
Ejemplo n.º 14
0
        public void TestQSResetsRecordLookup()
        {
            var c = new CodeContext();
            var qs = new DummyQueryReference();
            var v = Expression.Constant(10);
            c.Add(qs, v);

            c.GetReplacement(qs);
            var qsReferenced = c.GetAndResetQuerySourceLookups();
            Assert.AreEqual(0, c.GetAndResetQuerySourceLookups().Length, "# of qs lookups after a reset");
        }
Ejemplo n.º 15
0
 public CQReplacementExpression(CodeContext context, QueryModel model, QueryModelCacheLine val)
 {
     _context = context;
     _model = model;
     _oldVal = val;
 }
Ejemplo n.º 16
0
 public void TestAddNullExpression()
 {
     var c = new CodeContext();
     c.Add("dude", (Expression)null);
 }
Ejemplo n.º 17
0
        public void TestQMStoreResetsQSLookupList()
        {
            var c = new CodeContext();
            var qm = new QueryModel(new Remotion.Linq.Clauses.MainFromClause("dude", typeof(int), Expression.Parameter(typeof(IEnumerable<int>))),
                new Remotion.Linq.Clauses.SelectClause(Expression.Parameter(typeof(int))));

            var qs = new DummyQueryReference();
            c.Add(qs, Expression.Constant(10));
            c.GetReplacement(qs);

            var e1 = Expression.Parameter(typeof(int));
            var s1 = c.Add(qm, e1);

            Assert.AreEqual(0, c.GetAndResetQuerySourceLookups().Length, "# of qs references after a lookup");
        }
Ejemplo n.º 18
0
        public void TestQMInvalidedByQSChange()
        {
            var c = new CodeContext();
            var qm = new QueryModel(new Remotion.Linq.Clauses.MainFromClause("dude", typeof(int), Expression.Parameter(typeof(IEnumerable<int>))),
                new Remotion.Linq.Clauses.SelectClause(Expression.Parameter(typeof(int))));

            var qs = new DummyQueryReference();
            c.Add(qs, Expression.Constant(10));
            c.GetReplacement(qs);

            var e1 = Expression.Parameter(typeof(int));
            var s1 = c.Add(qm, e1);

            Assert.AreEqual(e1, c.GetReplacement(qm), "Initial lookup");
            c.Add(qs, Expression.Constant(20));
            Assert.IsNull(c.GetReplacement(qm), "Lookup after referenced QS has changed");
        }
Ejemplo n.º 19
0
        public void TestQSRecordLookup()
        {
            var c = new CodeContext();
            var qs = new DummyQueryReference();
            var v = Expression.Constant(10);
            c.Add(qs, v);

            Assert.AreEqual(0, c.GetAndResetQuerySourceLookups().Length, "# of query source look ups isn't zero initially");

            // Look up bogus and make sure it is null

            var qsNotStored = new DummyQueryReference();
            c.GetReplacement(qsNotStored);
            Assert.AreEqual(0, c.GetAndResetQuerySourceLookups().Length, "Dummy lookup shouldn't cache reference.");

            // Look up good one and make sure it worked.

            c.GetReplacement(qs);
            var qsReferenced = c.GetAndResetQuerySourceLookups();
            Assert.AreEqual(1, qsReferenced.Length, "# of qs lookups after a real reference");
            Assert.AreEqual(qs, qsReferenced[0], "QS recorded in lookup");
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Keep track of what to do to pop this guy off
 /// </summary>
 /// <param name="codeContext"></param>
 /// <param name="query"></param>
 /// <param name="expression"></param>
 public CCReplacementQuery(CodeContext codeContext, IQuerySource query, Expression expression)
 {
     this.codeContext = codeContext;
     this.query = query;
     this.expression = expression;
 }