コード例 #1
0
        public void test_THAT_contains_expression_with_custom_note_type_IS_valid()
        {
            var analyzer = new ContainsAnalyzer(null, null);
            Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Note)x["Count"]).Contains("foo");

            Assert.That(analyzer.IsValid(expr), Is.True);
        }
コード例 #2
0
        public void test_THAT_contains_expression_with_custom_text_type_and_variable_IS_valid()
        {
            var analyzer  = new ContainsAnalyzer(null, null);
            var stringVar = "Blah-blah-blah";
            Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Text)x["Count"]).Contains(stringVar);

            Assert.That(analyzer.IsValid(expr), Is.True);
        }
コード例 #3
0
        public void test_THAT_contains_expression_IS_determined_properly()
        {
            // arrange
            Expression <Func <SPListItem, bool> > expr = x => ((string)x["Count"]).Contains("foo");
            var operandBuilder = MockRepository.GenerateStub <IOperandBuilder>();

            operandBuilder.Stub(b => b.CreateFieldRefOperand(((MethodCallExpression)expr.Body).Object, null)).Return(null);
            operandBuilder.Stub(b => b.CreateValueOperandForNativeSyntax(((MethodCallExpression)expr.Body).Arguments[0])).Return(null);
            var analyzer = new ContainsAnalyzer(null, operandBuilder);

            // act
            var operation = analyzer.GetOperation(expr);

            //assert
            Assert.That(operation, Is.InstanceOf <ContainsOperation>());
        }
コード例 #4
0
ファイル: AnalyzerFactory.cs プロジェクト: sadomovalex/camlex
        public IAnalyzer Create(LambdaExpression expr)
        {
            ExpressionType exprType = expr.Body.NodeType;

            if (exprType == ExpressionType.AndAlso)
            {
                return(new AndAlsoAnalyzer(this.operationResultBuilder, this));
            }
            if (exprType == ExpressionType.OrElse)
            {
                return(new OrElseAnalyzer(this.operationResultBuilder, this));
            }
            if (exprType == ExpressionType.NewArrayInit)
            {
                return(new ArrayAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.GreaterThanOrEqual)
            {
                return(new GeqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.GreaterThan)
            {
                return(new GtAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.LessThanOrEqual)
            {
                return(new LeqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }
            if (exprType == ExpressionType.LessThan)
            {
                return(new LtAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }

            // it is important to check NotIncludes before Equality because sometimes !x[].Includes() is interpreted as x[].Includes() == False
            // and sometimes as Not(x[])
            var includesAnalyzer = new IncludesAnalyzer(operationResultBuilder, operandBuilder);

            if (includesAnalyzer.IsValid(expr))
            {
                return(includesAnalyzer);
            }

            var notIncludesAnalyzer = new NotIncludesAnalyzer(operationResultBuilder, operandBuilder);

            if (notIncludesAnalyzer.IsValid(expr))
            {
                return(notIncludesAnalyzer);
            }

            // it is not enough to check ExpressionType for IsNull operation.
            // We need also to check that right operand is null
            IsNullAnalyzer isNullAnalyzer;

            if (this.isNullExpression(expr, out isNullAnalyzer))
            {
                return(isNullAnalyzer);
            }
            // note that it is important to have check on IsNull before check on ExpressionType.Equal.
            // Because x["foo"] == null is also ExpressionType.Equal, but it should be translated
            // into <IsNull> instead of <Eq>
            if (exprType == ExpressionType.Equal)
            {
                return(new EqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }

            // it is not enough to check ExpressionType for IsNotNull operation.
            // We need also to check that right operand is null
            IsNotNullAnalyzer isNotNullAnalyzer;

            if (this.isNotNullExpression(expr, out isNotNullAnalyzer))
            {
                return(isNotNullAnalyzer);
            }
            // note that it is important to have check on IsNotNull before check on ExpressionType.NotEqual.
            // Because x["foo"] != null is also ExpressionType.NotEqual, but it should be translated
            // into <IsNotNull> instead of <Neq>
            if (exprType == ExpressionType.NotEqual)
            {
                return(new NeqAnalyzer(this.operationResultBuilder, this.operandBuilder));
            }

            var beginsWithAnalyzer = new BeginsWithAnalyzer(operationResultBuilder, operandBuilder);

            if (beginsWithAnalyzer.IsValid(expr))
            {
                return(beginsWithAnalyzer);
            }

            var containsAnalyzer = new ContainsAnalyzer(operationResultBuilder, operandBuilder);

            if (containsAnalyzer.IsValid(expr))
            {
                return(containsAnalyzer);
            }

            var dateRangesOverlapAnalyzer = new DateRangesOverlapAnalyzer(operationResultBuilder, operandBuilder);

            if (dateRangesOverlapAnalyzer.IsValid(expr))
            {
                return(dateRangesOverlapAnalyzer);
            }

            var membershipAnalyzer = new MembershipAnalyzer(operationResultBuilder, operandBuilder);

            if (membershipAnalyzer.IsValid(expr))
            {
                return(membershipAnalyzer);
            }

            var inAnalyzer = new InAnalyzer(operationResultBuilder, operandBuilder);

            if (inAnalyzer.IsValid(expr))
            {
                return(inAnalyzer);
            }

            var joinAnalyzer = new JoinAnalyzer(operationResultBuilder, operandBuilder);

            if (joinAnalyzer.IsValid(expr))
            {
                return(joinAnalyzer);
            }

            var projectedFieldAnalyzer = new ProjectedFieldAnalyzer(operationResultBuilder, operandBuilder);

            if (projectedFieldAnalyzer.IsValid(expr))
            {
                return(projectedFieldAnalyzer);
            }

            throw new NonSupportedExpressionTypeException(exprType);
        }
コード例 #5
0
        public IAnalyzer Create(LambdaExpression expr)
        {
            ExpressionType exprType = expr.Body.NodeType;

            if (exprType == ExpressionType.AndAlso)
            {
                return(new AndAlsoAnalyzer(this._operationResultBuilder, this));
            }
            if (exprType == ExpressionType.OrElse)
            {
                return(new OrElseAnalyzer(this._operationResultBuilder, this));
            }
            if (exprType == ExpressionType.NewArrayInit)
            {
                return(new ArrayAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }
            if (exprType == ExpressionType.GreaterThanOrEqual)
            {
                return(new GeqAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }
            if (exprType == ExpressionType.GreaterThan)
            {
                return(new GtAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }
            if (exprType == ExpressionType.LessThanOrEqual)
            {
                return(new LeqAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }
            if (exprType == ExpressionType.LessThan)
            {
                return(new LtAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }

            // it is not enough to check ExpressionType for IsNull operation.
            // We need also to check that right operand is null
            IsNullAnalyzer isNullAnalyzer;

            if (this.IsNullExpression(expr, out isNullAnalyzer))
            {
                return(isNullAnalyzer);
            }
            // note that it is important to have check on IsNull before check on ExpressionType.Equal.
            // Because x["foo"] == null is also ExpressionType.Equal, but it should be translated
            // into <IsNull> instead of <Eq>
            if (exprType == ExpressionType.Equal)
            {
                return(new EqAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }

            // it is not enough to check ExpressionType for IsNotNull operation.
            // We need also to check that right operand is null
            IsNotNullAnalyzer isNotNullAnalyzer;

            if (this.IsNotNullExpression(expr, out isNotNullAnalyzer))
            {
                return(isNotNullAnalyzer);
            }
            // note that it is important to have check on IsNotNull before check on ExpressionType.NotEqual.
            // Because x["foo"] != null is also ExpressionType.NotEqual, but it should be translated
            // into <IsNotNull> instead of <Neq>
            if (exprType == ExpressionType.NotEqual)
            {
                return(new NeqAnalyzer(this._operationResultBuilder, this._operandBuilder));
            }

            var beginsWithAnalyzer = new BeginsWithAnalyzer(_operationResultBuilder, _operandBuilder);

            if (beginsWithAnalyzer.IsValid(expr))
            {
                return(beginsWithAnalyzer);
            }

            var containsAnalyzer = new ContainsAnalyzer(_operationResultBuilder, _operandBuilder);

            if (containsAnalyzer.IsValid(expr))
            {
                return(containsAnalyzer);
            }

            throw new NonSupportedExpressionTypeException(exprType);
        }