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 BindApplyWithEntitySetAggregationReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); GroupByTransformationNode groupBy = actual.Transformations.First() as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); AggregateTransformationNode aggregate = groupBy.ChildTransformations as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateExpression entitySetAggregate = aggregate.AggregateExpressions.First() as EntitySetAggregateExpression; entitySetAggregate.Should().NotBeNull(); }
public void BindApplyWitMultipleTokensShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((ID, SSN, LifeTime))/aggregate(LifeTime with sum as TotalLife)/groupby((TotalLife))/aggregate(TotalLife with sum as TotalTotalLife)"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(4); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode firstGroupBy = transformations[0] as GroupByTransformationNode; firstGroupBy.Should().NotBeNull(); TransformationNode firstAggregate = transformations[1] as AggregateTransformationNode; firstAggregate.Should().NotBeNull(); TransformationNode scecondGroupBy = transformations[2] as GroupByTransformationNode; scecondGroupBy.Should().NotBeNull(); AggregateTransformationNode scecondAggregate = transformations[3] as AggregateTransformationNode; scecondAggregate.Should().NotBeNull(); }
public void BindApplyWithExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'))/groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState, V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet())); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(2); ExpandTransformationNode expand = actual.Transformations.First() as ExpandTransformationNode; expand.Should().NotBeNull(); expand.ExpandClause.Should().NotBeNull(); expand.ExpandClause.SelectedItems.Should().HaveCount(1); ExpandedNavigationSelectItem expandItem = expand.ExpandClause.SelectedItems.First() as ExpandedNavigationSelectItem; expandItem.Should().NotBeNull(); expandItem.NavigationSource.Name.ShouldBeEquivalentTo("Paintings"); expandItem.FilterOption.Should().NotBeNull(); GroupByTransformationNode groupBy = actual.Transformations.Last() as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); AggregateTransformationNode aggregate = groupBy.ChildTransformations as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateExpression entitySetAggregate = aggregate.AggregateExpressions.First() as EntitySetAggregateExpression; entitySetAggregate.Should().NotBeNull(); }
public void BindVirtualPropertiesAfterCollapseReturnsApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((ID))/aggregate($count as Count)"); BindingState state = new BindingState(_configuration); 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); GroupByTransformationNode groupby = actual.Transformations.First() as GroupByTransformationNode; groupby.Should().NotBeNull(); AggregateTransformationNode aggregate = actual.Transformations.Last() as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); aggregate.AggregateExpressions.Single().As <AggregateExpression>().Method.ShouldBeEquivalentTo(AggregationMethod.VirtualPropertyCount); }
public void BindApplyWithCountInAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("aggregate($count as TotalCount)"); 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.Expressions.Should().NotBeNull(); aggregate.Expressions.Should().HaveCount(1); List <AggregateExpression> statements = aggregate.Expressions.ToList(); AggregateExpression statement = statements[0]; statement.Method.Should().Be(AggregationMethod.VirtualPropertyCount); statement.Alias.Should().Be("TotalCount"); }
public void BindApplyWithEntitySetAggregationWithoutGroupByReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "aggregate(MyPaintings(Value with sum as TotalValue))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); AggregateTransformationNode aggregate = actual.Transformations.First() as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateExpression entitySetAggregate = aggregate.AggregateExpressions.First() as EntitySetAggregateExpression; entitySetAggregate.Should().NotBeNull(); }