コード例 #1
0
        public void BindApplyWithAggregateAndFilterShouldReturnApplyClause()
        {
            IEnumerable <QueryToken> tokens        = _parser.ParseApply("aggregate(StockQuantity with sum as TotalPrice)/filter(TotalPrice eq 100)");
            MetadataBinder           metadataBiner = new MetadataBinder(_bindingState);
            ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState);
            ApplyClause actual = binder.BindApply(tokens);

            Assert.NotNull(actual);
            Assert.Equal(2, actual.Transformations.Count());

            List <TransformationNode> transformations = actual.Transformations.ToList();

            Assert.NotNull(transformations[1]);
            FilterTransformationNode filter = Assert.IsType <FilterTransformationNode>(transformations[1]);

            Assert.Equal(TransformationNodeKind.Filter, filter.Kind);

            FilterClause filterClause = filter.FilterClause;

            Assert.NotNull(filterClause.Expression);
            BinaryOperatorNode binaryOperation = Assert.IsType <BinaryOperatorNode>(filterClause.Expression);

            Assert.NotNull(binaryOperation.Left);
            ConvertNode propertyConvertNode = Assert.IsType <ConvertNode>(binaryOperation.Left);

            Assert.NotNull(propertyConvertNode.Source);
            SingleValueOpenPropertyAccessNode propertyAccess = Assert.IsType <SingleValueOpenPropertyAccessNode>(propertyConvertNode.Source);

            Assert.Equal("TotalPrice", propertyAccess.Name);
        }
コード例 #2
0
        public void BindApplyWithAggregateAndFilterShouldReturnApplyClause()
        {
            IEnumerable <QueryToken> tokens        = _parser.ParseApply("aggregate(StockQuantity with sum as TotalPrice)/filter(TotalPrice eq 100)");
            MetadataBinder           metadataBiner = new MetadataBinder(_bindingState);
            ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState);
            ApplyClause actual = binder.BindApply(tokens);

            actual.Should().NotBeNull();
            actual.Transformations.Should().HaveCount(2);

            List <TransformationNode> transformations = actual.Transformations.ToList();
            FilterTransformationNode  filter          = transformations[1] as FilterTransformationNode;

            filter.Should().NotBeNull();
            filter.Kind.Should().Be(TransformationNodeKind.Filter);

            FilterClause filterClause = filter.FilterClause;

            filterClause.Expression.Should().NotBeNull();
            BinaryOperatorNode binaryOperation = filterClause.Expression as BinaryOperatorNode;

            binaryOperation.Should().NotBeNull();
            ConvertNode propertyConvertNode = binaryOperation.Left as ConvertNode;

            propertyConvertNode.Should().NotBeNull();
            SingleValueOpenPropertyAccessNode propertyAccess = propertyConvertNode.Source as SingleValueOpenPropertyAccessNode;

            propertyAccess.Should().NotBeNull();
            propertyAccess.Name.Should().Be("TotalPrice");
        }
コード例 #3
0
        public ApplyClause BindApply(IEnumerable <QueryToken> tokens)
        {
            ExceptionUtils.CheckArgumentNotNull(tokens, "tokens");

            var transformations = new List <TransformationNode>();

            foreach (var token in tokens)
            {
                switch (token.Kind)
                {
                case QueryTokenKind.Aggregate:
                    var aggregate = BindAggregateToken((AggregateToken)(token));
                    transformations.Add(aggregate);
                    aggregateStatementsCache   = aggregate.Statements;
                    state.AggregatedProperties =
                        aggregate.Statements.Select(statement => statement.AsAlias).ToList();
                    break;

                case QueryTokenKind.AggregateGroupBy:
                    var groupBy = BindGroupByToken((GroupByToken)(token));
                    transformations.Add(groupBy);
                    break;

                default:
                    var filterClause = this.filterBinder.BindFilter(token);
                    var filterNode   = new FilterTransformationNode(filterClause);
                    transformations.Add(filterNode);
                    break;
                }
            }

            return(new ApplyClause(transformations));
        }
コード例 #4
0
        public void BindApplyWitFilterShouldReturnApplyClause()
        {
            IEnumerable <QueryToken> tokens = _parser.ParseApply("filter(UnitPrice eq 5)");

            ApplyBinder binder = new ApplyBinder(BindMethodReturnsBooleanPrimitive, _bindingState);
            ApplyClause actual = binder.BindApply(tokens);

            actual = binder.BindApply(tokens);

            Assert.NotNull(actual);

            FilterTransformationNode filter = Assert.IsType <FilterTransformationNode>(Assert.Single(actual.Transformations));

            Assert.Equal(TransformationNodeKind.Filter, filter.Kind);
            Assert.NotNull(filter.FilterClause.Expression);
            Assert.Same(_booleanPrimitiveNode, filter.FilterClause.Expression);
        }
コード例 #5
0
        private MethodCallExpression ApplyFilter(Expression source, FilterTransformationNode transformation)
        {
            Type sourceType = OeExpressionHelper.GetCollectionItemType(source.Type);
            ParameterExpression sourceParameter = Expression.Parameter(sourceType);

            var visitor = CreateVisitor(sourceParameter);

            if (_aggProperties.Count > 0)
            {
                visitor.TuplePropertyByAliasName = GetTuplePropertyByAliasName;
            }
            Expression e = visitor.TranslateNode(transformation.FilterClause.Expression);

            MethodInfo       whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(sourceParameter.Type);
            LambdaExpression lambda          = Expression.Lambda(e, sourceParameter);

            return(Expression.Call(whereMethodInfo, source, lambda));
        }
コード例 #6
0
        public void BindApplyWitFilterShouldReturnApplyClause()
        {
            IEnumerable <QueryToken> tokens = _parser.ParseApply("filter(UnitPrice eq 5)");

            ApplyBinder binder = new ApplyBinder(BindMethodReturnsBooleanPrimitive, _bindingState);
            ApplyClause actual = binder.BindApply(tokens);

            actual = binder.BindApply(tokens);

            actual.Should().NotBeNull();
            actual.Transformations.Should().HaveCount(1);

            List <TransformationNode> transformations = actual.Transformations.ToList();
            FilterTransformationNode  filter          = transformations[0] as FilterTransformationNode;

            filter.Should().NotBeNull();
            filter.Kind.Should().Be(TransformationNodeKind.Filter);
            filter.FilterClause.Expression.Should().NotBeNull();
            filter.FilterClause.Expression.Should().BeSameAs(_booleanPrimitiveNode);
        }
コード例 #7
0
 private void Translate(FilterTransformationNode transformation)
 {
     AppendExpression(transformation.FilterClause.Expression);
 }