Ejemplo n.º 1
0
        public void TestThatBeginsWithExpressionWithCustomNoteTypeIsValid()
        {
            var analyzer = new BeginsWithAnalyzer(null, null);
            Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Note)x["Count"]).StartsWith("foo");

            Assert.That(analyzer.IsValid(expr), Is.True);
        }
Ejemplo n.º 2
0
        public void test_THAT_beginswith_expression_with_string_type_IS_valid()
        {
            var analyzer = new BeginsWithAnalyzer(null, null);
            Expression <Func <SPListItem, bool> > expr = x => ((string)x["Count"]).StartsWith("foo");

            Assert.That(analyzer.IsValid(expr), Is.True);
        }
Ejemplo n.º 3
0
        public void TestThatBeginsWithExpressionWithCustomNoteTypeAndVariableIsValid()
        {
            var analyzer  = new BeginsWithAnalyzer(null, null);
            var stringVar = "Blah-blah-blah";
            Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Note)x["Count"]).StartsWith(stringVar);

            Assert.That(analyzer.IsValid(expr), Is.True);
        }
Ejemplo n.º 4
0
        public void test_THAT_beginswith_expression_with_string_variable_as_indexer_param_IS_valid()
        {
            var analyzer = new BeginsWithAnalyzer(null, null);

            string val = "Count";
            Expression <Func <SPListItem, bool> > expr = x => ((string)x[val]).StartsWith("foo");

            Assert.That(analyzer.IsValid(expr), Is.True);
        }
Ejemplo n.º 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 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);
        }
Ejemplo n.º 6
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);
        }