示例#1
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");
        }
示例#2
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");
        }
示例#3
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");
        }
示例#4
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");
        }
示例#5
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");
        }
示例#6
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");
        }
示例#7
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");
 }
示例#8
0
        public void TestAddQueryReferenceSource()
        {
            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.");
        }
示例#9
0
 /// <summary>
 /// Remove the variable.
 /// </summary>
 public void Pop()
 {
     if (expression == null)
     {
         codeContext.DeleteValue(query);
     }
     else
     {
         codeContext.Add(query, expression);
     }
 }
示例#10
0
 /// <summary>
 /// Go back to what we had!
 /// </summary>
 public void Pop()
 {
     if (_oldVal != null)
     {
         _context.Add(_varName, _oldVal);
     }
     else
     {
         _context.DeleteExpression(_varName);
     }
 }
示例#11
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");
        }
示例#12
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");
        }
示例#13
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");
        }
示例#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");
        }
示例#15
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.");
        }
示例#16
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");
        }
示例#17
0
        public void TestAddNullExpression()
        {
            var c = new CodeContext();

            c.Add("dude", (Expression)null);
        }
示例#18
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");
        }
示例#19
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.");
        }
示例#20
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");
        }
示例#21
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");
        }
示例#22
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");
        }
示例#23
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.");
        }
示例#24
0
 public void TestAddNullExpression()
 {
     var c = new CodeContext();
     c.Add("dude", (Expression)null);
 }