public void BindApplyWithAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("aggregate(UnitPrice with sum as TotalPrice)"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); AggregateTransformationNode aggregate = transformations[0] as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.Kind.Should().Be(TransformationNodeKind.Aggregate); aggregate.AggregateExpressions.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); List <AggregateExpressionBase> statements = aggregate.AggregateExpressions.ToList(); AggregateExpression statement = statements[0] as AggregateExpression; statement.Should().NotBeNull(); VerifyIsFakeSingleValueNode(statement.Expression); statement.Method.Should().Be(AggregationMethod.Sum); statement.Alias.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.EnableCaseInsensitiveUriFunctionIdentifier); 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 BindApplyWithAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("aggregate(UnitPrice with sum as TotalPrice)"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); AggregateTransformationNode aggregate = Assert.IsType <AggregateTransformationNode>(Assert.Single(actual.Transformations)); Assert.Equal(TransformationNodeKind.Aggregate, aggregate.Kind); Assert.NotNull(aggregate.AggregateExpressions); AggregateExpression statement = Assert.IsType <AggregateExpression>(Assert.Single(aggregate.AggregateExpressions)); VerifyIsFakeSingleValueNode(statement.Expression); Assert.Equal(AggregationMethod.Sum, statement.Method); Assert.Equal("TotalPrice", statement.Alias); }