public void test_THAT_includes_expression_with_custom_note_type_IS_valid() { var analyzer = new IncludesAnalyzer(null, null); Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Note)x["Count"]).Includes("foo"); Assert.That(analyzer.IsValid(expr), Is.True); }
public void test_THAT_includes_expression_with_string_type_and_lookupid_IS_valid() { var analyzer = new IncludesAnalyzer(null, null); Expression <Func <SPListItem, bool> > expr = x => ((string)x["Count"]).Includes("foo", true); Assert.That(analyzer.IsValid(expr), Is.True); }
public void test_THAT_includes_expression_with_int_type_IS_valid() { var analyzer = new IncludesAnalyzer(null, null); Expression <Func <SPListItem, bool> > expr = x => ((int)x["Count"]).Includes(1); Assert.That(analyzer.IsValid(expr), Is.True); }
public void test_THAT_includes_expression_with_custom_text_type_and_variable_IS_valid() { var analyzer = new IncludesAnalyzer(null, null); var stringVar = "Blah-blah-blah"; Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Text)x["Count"]).Includes(stringVar); Assert.That(analyzer.IsValid(expr), Is.True); }
public void test_THAT_includes_expression_with_custom_note_type_IS_determined_properly() { // arrange Expression <Func <SPListItem, bool> > expr = x => ((DataTypes.Note)x["Count"]).Includes("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 IncludesAnalyzer(null, operandBuilder); // act var operation = analyzer.GetOperation(expr); //assert Assert.That(operation, Is.InstanceOf <IncludesOperation>()); }
public override IOperation GetOperation(LambdaExpression expr) { if (!IsValid(expr)) { throw new NonSupportedExpressionException(expr); } // var fieldRefOperand = getFieldRefOperand(expr); // var valueOperand = getValueOperand(expr); // return new NotIncludesOperation(operationResultBuilder, fieldRefOperand, valueOperand); var subExpr = this.getSubExpr(expr); var includesAnalyzer = new IncludesAnalyzer(this.operationResultBuilder, this.operandBuilder); var includesOperation = (IncludesOperation)includesAnalyzer.GetOperation(Expression.Lambda(subExpr, expr.Parameters)); return(new NotIncludesOperation(operationResultBuilder, includesOperation.FieldRefOperand, includesOperation.ValueOperand)); }
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); }