Пример #1
0
 public override void SetUp ()
 {
   base.SetUp ();
   
   var predicate = ExpressionHelper.CreateLambdaExpression<int, bool> (i => i > 5);
   _node = new WhereExpressionNode (CreateParseInfo (), predicate);
 }
Пример #2
0
        protected ResultOperatorExpressionNodeBase(
            MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate, LambdaExpression optionalSelector)
            : base(parseInfo)
        {
            if (optionalPredicate != null && optionalPredicate.Parameters.Count != 1)
            {
                throw new ArgumentException("OptionalPredicate must have exactly one parameter.", "optionalPredicate");
            }

            if (optionalSelector != null && optionalSelector.Parameters.Count != 1)
            {
                throw new ArgumentException("OptionalSelector must have exactly one parameter.", "optionalSelector");
            }

            if (optionalPredicate != null)
            {
                Source = new WhereExpressionNode(parseInfo, optionalPredicate);
            }

            if (optionalSelector != null)
            {
                var newParseInfo = new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, Source, parseInfo.ParsedExpression);
                Source = new SelectExpressionNode(newParseInfo, optionalSelector);
            }

            ParsedExpression = parseInfo.ParsedExpression;
        }
Пример #3
0
    public void GetResolvedPredicate ()
    {
      var predicate = ExpressionHelper.CreateLambdaExpression<int, bool> (i => i > 5);
      var node = new WhereExpressionNode (CreateParseInfo (), predicate);

      var expectedResult = Expression.MakeBinary (ExpressionType.GreaterThan, SourceReference, Expression.Constant (5));

      var result = node.GetResolvedPredicate (ClauseGenerationContext);

      ExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result);
    }
Пример #4
0
    public void Resolve_PassesExpressionToSource ()
    {
      var sourceMock = MockRepository.GenerateMock<IExpressionNode>();
      var predicate = ExpressionHelper.CreateLambdaExpression<int, bool> (i => i > 5);
      var node = new WhereExpressionNode (CreateParseInfo (sourceMock), predicate);
      var expression = ExpressionHelper.CreateLambdaExpression();
      var parameter = ExpressionHelper.CreateParameterExpression();
      var expectedResult = ExpressionHelper.CreateExpression();
      sourceMock.Expect (mock => mock.Resolve (parameter, expression, ClauseGenerationContext)).Return (expectedResult);

      var result = node.Resolve (parameter, expression, ClauseGenerationContext);

      sourceMock.VerifyAllExpectations();
      Assert.That (result, Is.SameAs (expectedResult));
    }
    private static MethodCallExpressionParseInfo TransformParseInfo (
        MethodCallExpressionParseInfo parseInfo,
        LambdaExpression optionalPredicate,
        LambdaExpression optionalSelector)
    {
      var source = parseInfo.Source;

      if (optionalPredicate != null)
        source = new WhereExpressionNode (parseInfo, optionalPredicate);

      if (optionalSelector != null)
      {
        var newParseInfo = new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
        source = new SelectExpressionNode (newParseInfo, optionalSelector);
      }

      return new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
    }
        private static MethodCallExpressionParseInfo TransformParseInfo(
            MethodCallExpressionParseInfo parseInfo,
            LambdaExpression optionalPredicate,
            LambdaExpression optionalSelector)
        {
            var source = parseInfo.Source;

            if (optionalPredicate != null)
            {
                source = new WhereExpressionNode(parseInfo, optionalPredicate);
            }

            if (optionalSelector != null)
            {
                var newParseInfo = new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
                source = new SelectExpressionNode(newParseInfo, optionalSelector);
            }

            return(new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression));
        }
        protected ResultOperatorExpressionNodeBase(
        MethodCallExpressionParseInfo parseInfo, LambdaExpression optionalPredicate, LambdaExpression optionalSelector)
            : base(parseInfo)
        {
            if (optionalPredicate != null && optionalPredicate.Parameters.Count != 1)
            throw new ArgumentException ("OptionalPredicate must have exactly one parameter.", "optionalPredicate");

              if (optionalSelector != null && optionalSelector.Parameters.Count != 1)
            throw new ArgumentException ("OptionalSelector must have exactly one parameter.", "optionalSelector");

              if (optionalPredicate != null)
            Source = new WhereExpressionNode (parseInfo, optionalPredicate);

              if (optionalSelector != null)
              {
            var newParseInfo = new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, Source, parseInfo.ParsedExpression);
            Source = new SelectExpressionNode (newParseInfo, optionalSelector);
              }

              ParsedExpression = parseInfo.ParsedExpression;
        }