public void BindApplyWithAggregateAndFilterShouldReturnApplyClause() { var tokens = _parser.ParseApply("aggregate(StockQuantity with sum as TotalPrice)/filter(TotalPrice eq 100)"); var metadataBiner = new MetadataBinder(_bindingState); var binder = new ApplyBinder(metadataBiner.Bind, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(2); var transformations = actual.Transformations.ToList(); var filter = transformations[1] as FilterTransformationNode; filter.Should().NotBeNull(); filter.Kind.Should().Be(TransformationNodeKind.Filter); var filtareClause = filter.FilterClause; filtareClause.Expression.Should().NotBeNull(); var binaryOperation = filtareClause.Expression as BinaryOperatorNode; binaryOperation.Should().NotBeNull(); var propertyConvertNode = binaryOperation.Left as ConvertNode; propertyConvertNode.Should().NotBeNull(); var propertyAccess = propertyConvertNode.Source as SingleValueOpenPropertyAccessNode; propertyAccess.Should().NotBeNull(); propertyAccess.Name.Should().Be("TotalPrice"); }
public void BindApplyWithAggregateShouldReturnApplyClause() { var tokens = _parser.ParseApply("aggregate(UnitPrice with sum as TotalPrice)"); var binder = new ApplyBinder(FakeBindMethods.BindSingleValueProperty, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); var transformations = actual.Transformations.ToList(); var aggregate = transformations[0] as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.Kind.Should().Be(TransformationNodeKind.Aggregate); aggregate.Statements.Should().NotBeNull(); aggregate.Statements.Should().HaveCount(1); var statements = aggregate.Statements.ToList(); var statement = statements[0]; VerifyIsFakeSingleValueNode(statement.Expression); statement.WithVerb.Should().Be(AggregationVerb.Sum); statement.AsAlias.Should().Be("TotalPrice"); }
/// <summary> /// Parses an <paramref name="apply"/> clause on the given <paramref name="elementType"/>, binding /// the text into a metadata-bound or dynamic properties to be applied using the provided model. /// </summary> /// <param name="apply">String representation of the apply expression.</param> /// <param name="configuration">The configuration used for binding.</param> /// <param name="elementType">Type that the apply clause refers to.</param> /// <param name="navigationSource">Navigation source that the elements being filtered are from.</param> /// <returns>A <see cref="ApplyClause"/> representing the metadata bound apply expression.</returns> private static ApplyClause ParseApplyImplementation(string apply, ODataUriParserConfiguration configuration, IEdmType elementType, IEdmNavigationSource navigationSource) { ExceptionUtils.CheckArgumentNotNull(configuration, "configuration"); ExceptionUtils.CheckArgumentNotNull(elementType, "elementType"); ExceptionUtils.CheckArgumentNotNull(apply, "apply"); // Get the syntactic representation of the apply expression UriQueryExpressionParser expressionParser = new UriQueryExpressionParser(configuration.Settings.FilterLimit, configuration.EnableCaseInsensitiveBuiltinIdentifier); var applyTokens = expressionParser.ParseApply(apply); // Bind it to metadata BindingState state = new BindingState(configuration); state.ImplicitRangeVariable = NodeFactory.CreateImplicitRangeVariable(elementType.ToTypeReference(), navigationSource); state.RangeVariables.Push(state.ImplicitRangeVariable); MetadataBinder binder = new MetadataBinder(state); ApplyBinder applyBinder = new ApplyBinder(binder.Bind, state); ApplyClause boundNode = applyBinder.BindApply(applyTokens); return boundNode; }
public void BindApplyWithNullShouldThrow() { var binder = new ApplyBinder(FakeBindMethods.BindSingleValueProperty, _bindingState); Action bind = () => binder.BindApply(null); bind.ShouldThrow<ArgumentNullException>(); }
public void BindApplyWitMultipleTokensShouldReturnApplyClause() { var tokens = _parser.ParseApply( "groupby((ID, SSN, LifeTime))/aggregate(LifeTime with sum as TotalLife)/groupby((TotalLife))/aggregate(TotalLife with sum as TotalTotalLife)"); var state = new BindingState(_configuration); var metadataBiner = new MetadataBinder(_bindingState); var binder = new ApplyBinder(metadataBiner.Bind, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(4); var transformations = actual.Transformations.ToList(); var firstGroupBy = transformations[0] as GroupByTransformationNode; firstGroupBy.Should().NotBeNull(); var firstAggregate = transformations[1] as AggregateTransformationNode; firstAggregate.Should().NotBeNull(); var scecondGroupBy = transformations[2] as GroupByTransformationNode; scecondGroupBy.Should().NotBeNull(); var scecondAggregate = transformations[3] as AggregateTransformationNode; scecondAggregate.Should().NotBeNull(); }
public void BindApplyWitFilterShouldReturnApplyClause() { var tokens = _parser.ParseApply("filter(UnitPrice eq 5)"); var binder = new ApplyBinder(BindMethodReturnsBooleanPrimitive, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); var transformations = actual.Transformations.ToList(); var 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); }
public void BindApplyWitGroupByWithAggregateShouldReturnApplyClause() { var tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice), aggregate(UnitPrice with sum as TotalPrice))"); var binder = new ApplyBinder(FakeBindMethods.BindSingleValueProperty, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); var transformations = actual.Transformations.ToList(); var groupBy = transformations[0] as GroupByTransformationNode; var aggregate = groupBy.ChildTransformation; aggregate.Should().NotBeNull(); }
public void BindApplyWitGroupByWithNavigationShouldReturnApplyClause() { var tokens = _parser.ParseApply("groupby((MyDog/City))"); var binder = new ApplyBinder(FakeBindMethods.BindMethodReturnsPersonDogNameNavigation, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); var transformations = actual.Transformations.ToList(); var groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); var groupingProperties = groupBy.GroupingProperties.ToList(); var dogNode = groupingProperties[0]; dogNode.Accessor.Should().BeNull(); dogNode.Name.Should().Be("MyDog"); dogNode.Children.Should().HaveCount(1); var nameNode = dogNode.Children[0]; dogNode.Name.Should().Be("MyDog"); nameNode.Accessor.Should().BeSameAs(FakeBindMethods.FakePersonDogNameNode); groupBy.ChildTransformation.Should().BeNull(); }
public void BindApplyWitGroupByShouldReturnApplyClause() { var tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice))"); var binder = new ApplyBinder(FakeBindMethods.BindSingleValueProperty, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); var transformations = actual.Transformations.ToList(); var groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(2); var groupingProperties = groupBy.GroupingProperties.ToList(); VerifyIsFakeSingleValueNode(groupingProperties[0].Accessor); VerifyIsFakeSingleValueNode(groupingProperties[1].Accessor); groupBy.ChildTransformation.Should().BeNull(); }