Exemplo n.º 1
0
        public void ItCanVisitAMultipleColumnSelector()
        {
            Expression <Func <Person, object> > func = (Person p) => new { p.Age, p.Name };
            var tableRef = Types.TableReferenceFromType <Person>();
            var ev       = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                new[] { tableRef }.ToContext()
                );

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] { S.Col <Person>("Age"), S.Col <Person>("Name") })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Exemplo n.º 2
0
        public void ItShouldNotGenerateAliasColumnsForColumnsBeingAliasedToItsOrdinaryName()
        {
            Expression <Func <Person, object> > func = (Person p) => new { Name = p.Name, Age = p.Age };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());
            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.Col <Person>("Name"),
                S.Col <Person>("Age"),
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Exemplo n.º 3
0
        public void ItShouldBeAbleToGenerateAliasesForConstants()
        {
            Expression <Func <Person, object> > func = (Person p) => new { FavoriteNumber = 42 };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.AliasedCol(S.Const(42), "FavoriteNumber"),
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Exemplo n.º 4
0
        public void ItShouldBeAbleToGenerateAliasesForBinaryExpressions()
        {
            Expression <Func <Person, object> > func = (Person p) => new { AgePlusTen = p.Age + 10 };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.AliasedCol(S.BinExp(S.Col <Person>("Age"), BinaryOperation.Add, S.Const(10)), "AgePlusTen"),
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Exemplo n.º 5
0
        public void ItShouldBeAbleToGenerateAliasedColumnTokens()
        {
            Expression <Func <Person, object> > func = (Person p) => new { p.Name, AgeOfPerson = p.Age, Count = Sql.Count() };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.Col <Person>("Name"),
                S.AliasedCol <Person>("Age", "AgeOfPerson"),
                S.AliasedCol <Person>(AST.AggregateType.Count, S.Null(), "Count")
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }