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)); }
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)); }
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)); }
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)); }
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)); }