public void GetResolvedResultSelector() { _nodeWithResultSelector.Apply(QueryModel, ClauseGenerationContext); var clause = (FromClauseBase)QueryModel.BodyClauses[0]; var expectedResult = Expression.MakeBinary(ExpressionType.GreaterThan, SourceReference, new QuerySourceReferenceExpression(clause)); var result = _nodeWithResultSelector.GetResolvedResultSelector(ClauseGenerationContext); ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result); }
public void Resolve_ReplacesParameter_WithProjection() { var node = new SelectManyExpressionNode( CreateParseInfo(), _collectionSelector, ExpressionHelper.CreateLambdaExpression <int, int, AnonymousType> ((a, b) => new AnonymousType(a, b))); node.Apply(QueryModel, ClauseGenerationContext); var clause = (FromClauseBase)QueryModel.BodyClauses[0]; var expression = ExpressionHelper.CreateLambdaExpression <AnonymousType, bool> (i => i.a > 5 && i.b > 6); var result = node.Resolve(expression.Parameters[0], expression.Body, ClauseGenerationContext); var selectManySourceReference = new QuerySourceReferenceExpression(clause); // new AnonymousType (SourceReference, selectManySourceReference).a > 5 && new AnonymousType (SourceReference, selectManySourceReference).b > 6 var newAnonymousTypeExpression = Expression.New( typeof(AnonymousType).GetConstructor(new[] { typeof(int), typeof(int) }), SourceReference, selectManySourceReference); var anonymousTypeMemberAExpression = Expression.MakeMemberAccess(newAnonymousTypeExpression, typeof(AnonymousType).GetProperty("a")); var anonymousTypeMemberBExpression = Expression.MakeMemberAccess(newAnonymousTypeExpression, typeof(AnonymousType).GetProperty("b")); var expectedResult = Expression.MakeBinary( ExpressionType.AndAlso, Expression.MakeBinary(ExpressionType.GreaterThan, anonymousTypeMemberAExpression, Expression.Constant(5)), Expression.MakeBinary(ExpressionType.GreaterThan, anonymousTypeMemberBExpression, Expression.Constant(6))); ExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result); }