public void BindApplyWithNullShouldThrow() { var binder = new ApplyBinder(FakeBindMethods.BindSingleValueProperty, _bindingState); Action bind = () => binder.BindApply(null); bind.ShouldThrow <ArgumentNullException>(); }
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.Expressions.Should().NotBeNull(); aggregate.Expressions.Should().HaveCount(1); var statements = aggregate.Expressions.ToList(); var statement = statements[0]; VerifyIsFakeSingleValueNode(statement.Expression); statement.Method.Should().Be(AggregationMethod.Sum); statement.Alias.Should().Be("TotalPrice"); }
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 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 BindApplyWitGroupByWithNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/City))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindMethodReturnsPersonDogColorNavigation, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(Assert.Single(actual.Transformations)); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode dogNode = Assert.Single(groupBy.GroupingProperties); Assert.Null(dogNode.Expression); Assert.Equal("MyDog", dogNode.Name); Assert.NotNull(dogNode.ChildTransformations); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode colorNode = Assert.Single(dogNode.ChildTransformations); Assert.Equal("Color", colorNode.Name); Assert.Same(FakeBindMethods.FakePersonDogColorNode, colorNode.Expression); Assert.Empty(colorNode.ChildTransformations); }
public void BindApplyWithNestedExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'), expand(Owner, filter(Name eq 'Me')))"); 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); Assert.NotNull(actual); ExpandTransformationNode expand = Assert.IsType <ExpandTransformationNode>(Assert.Single(actual.Transformations)); Assert.NotNull(expand.ExpandClause); ExpandedNavigationSelectItem expandItem = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expand.ExpandClause.SelectedItems)); Assert.Equal("Paintings", expandItem.NavigationSource.Name); Assert.NotNull(expandItem.SelectAndExpand); Assert.NotNull(expandItem.FilterOption); ExpandedNavigationSelectItem expandItem1 = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expandItem.SelectAndExpand.SelectedItems)); Assert.NotNull(expandItem1.FilterOption); }
public void BindApplyWitGroupByWithComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyAddress/City))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode addressNode = groupingProperties[0]; addressNode.Name.Should().Be("MyAddress"); addressNode.Expression.Should().BeNull(); addressNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode cityNode = addressNode.ChildTransformations[0]; cityNode.Name.Should().Be("City"); cityNode.Expression.Should().NotBeNull(); cityNode.ChildTransformations.Should().BeEmpty(); }
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].Expression); VerifyIsFakeSingleValueNode(groupingProperties[1].Expression); groupBy.ChildTransformations.Should().BeNull(); }
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); Assert.NotNull(actual); Assert.Equal(4, actual.Transformations.Count()); List <TransformationNode> transformations = actual.Transformations.ToList(); Assert.NotNull(transformations[0]); Assert.IsType <GroupByTransformationNode>(transformations[0]); Assert.NotNull(transformations[1]); Assert.IsType <AggregateTransformationNode>(transformations[1]); Assert.NotNull(transformations[2]); Assert.IsType <GroupByTransformationNode>(transformations[2]); Assert.NotNull(transformations[3]); Assert.IsType <AggregateTransformationNode>(transformations[3]); }
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.Expression.Should().BeNull(); dogNode.Name.Should().Be("MyDog"); dogNode.ChildTransformations.Should().HaveCount(1); var nameNode = dogNode.ChildTransformations[0]; dogNode.Name.Should().Be("MyDog"); nameNode.Expression.Should().BeSameAs(FakeBindMethods.FakePersonDogNameNode); groupBy.ChildTransformations.Should().BeNull(); }
public void BindApplyWitGroupByWithComplexAndNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyAddress/PostBoxPainting/Artist))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); var transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.Null(groupBy.ChildTransformations); Assert.NotNull(groupBy.GroupingProperties); GroupByPropertyNode addressNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyAddress", addressNode.Name); Assert.Null(addressNode.Expression); GroupByPropertyNode postBoxPaintingNode = Assert.Single(addressNode.ChildTransformations); Assert.Equal("PostBoxPainting", postBoxPaintingNode.Name); Assert.Null(postBoxPaintingNode.Expression); GroupByPropertyNode artistNode = Assert.Single(postBoxPaintingNode.ChildTransformations); Assert.Equal("Artist", artistNode.Name); Assert.NotNull(artistNode.Expression); Assert.Empty(artistNode.ChildTransformations); }
public void BindApplyWithNullShouldThrow() { ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); Action bind = () => binder.BindApply(null); Assert.Throws <ArgumentNullException>("tokens", bind); }
public void BindApplyWitGroupByWithDeepNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/FastestOwner/FirstName))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); TransformationNode transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode dogNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyDog", dogNode.Name); Assert.Null(dogNode.Expression); GroupByPropertyNode ownerNode = Assert.Single(dogNode.ChildTransformations); Assert.Equal("FastestOwner", ownerNode.Name); Assert.Null(ownerNode.Expression); GroupByPropertyNode nameNode = Assert.Single(ownerNode.ChildTransformations); Assert.Equal("FirstName", nameNode.Name); Assert.NotNull(nameNode.Expression); Assert.Empty(nameNode.ChildTransformations); }
public void BindApplyWitGroupByWithDeepComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyAddress/NextHome/City))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); var transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode addressNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyAddress", addressNode.Name); Assert.Null(addressNode.Expression); GroupByPropertyNode nextHomeNode = Assert.Single(addressNode.ChildTransformations); Assert.Equal("NextHome", nextHomeNode.Name); Assert.Null(nextHomeNode.Expression); GroupByPropertyNode cityNode = Assert.Single(nextHomeNode.ChildTransformations); Assert.Equal("City", cityNode.Name); Assert.NotNull(cityNode.Expression); Assert.Empty(cityNode.ChildTransformations); }
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); Assert.NotNull(actual); Assert.Equal(2, actual.Transformations.Count()); ExpandTransformationNode expand = Assert.IsType <ExpandTransformationNode>(actual.Transformations.First()); Assert.NotNull(expand.ExpandClause); ExpandedNavigationSelectItem expandItem = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expand.ExpandClause.SelectedItems)); Assert.Equal("Paintings", expandItem.NavigationSource.Name); Assert.NotNull(expandItem.FilterOption); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(actual.Transformations.Last()); Assert.Single(groupBy.GroupingProperties); AggregateTransformationNode aggregate = Assert.IsType <AggregateTransformationNode>(groupBy.ChildTransformations); Assert.IsType <EntitySetAggregateExpression>(Assert.Single(aggregate.AggregateExpressions)); }
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); }
public void BindApplyWithNestedExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'), expand(Owner, filter(Name eq 'Me')))"); 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(1); 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.SelectAndExpand.Should().NotBeNull(); expandItem.SelectAndExpand.SelectedItems.Should().HaveCount(1); expandItem.FilterOption.Should().NotBeNull(); ExpandedNavigationSelectItem expandItem1 = expandItem.SelectAndExpand.SelectedItems.First() as ExpandedNavigationSelectItem; expandItem1.FilterOption.Should().NotBeNull(); }
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 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); }
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); }
/// <summary> /// Bind the apply clause <see cref="ApplyClause"/> at this level. /// </summary> /// <param name="applyOptions">The apply options to visit.</param> /// <returns>The null or the built apply clause.</returns> private ApplyClause BindApply(IEnumerable <QueryToken> applyToken, IEdmNavigationSource navigationSource) { if (applyToken != null && applyToken.Any()) { MetadataBinder binder = BuildNewMetadataBinder(this.Configuration, navigationSource, null); ApplyBinder applyBinder = new ApplyBinder(binder.Bind, binder.BindingState); return(applyBinder.BindApply(applyToken)); } return(null); }
public void BindApplyWitGroupByWithAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice), aggregate(UnitPrice with sum as TotalPrice))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(Assert.Single(actual.Transformations)); Assert.NotNull(groupBy.ChildTransformations); }
public void BindApplyWitGroupByWithNavigationAndDeepComplexAndNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyFavoritePainting/ArtistAddress/NextHome/PostBoxPainting/Artist))"); 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); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode favoritePaintingNode = groupingProperties[0]; favoritePaintingNode.Name.Should().Be("MyFavoritePainting"); favoritePaintingNode.Expression.Should().BeNull(); favoritePaintingNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode artistAddressNode = favoritePaintingNode.ChildTransformations[0]; artistAddressNode.Name.Should().Be("ArtistAddress"); artistAddressNode.Expression.Should().BeNull(); artistAddressNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode nextHomeNode = artistAddressNode.ChildTransformations[0]; nextHomeNode.Name.Should().Be("NextHome"); nextHomeNode.Expression.Should().BeNull(); nextHomeNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode postBoxPaintingNode = nextHomeNode.ChildTransformations[0]; postBoxPaintingNode.Name.Should().Be("PostBoxPainting"); postBoxPaintingNode.Expression.Should().BeNull(); postBoxPaintingNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode artistNode = postBoxPaintingNode.ChildTransformations[0]; artistNode.Name.Should().Be("Artist"); artistNode.Expression.Should().NotBeNull(); artistNode.ChildTransformations.Should().BeEmpty(); }
public void BindApplyWithMultipleGroupBysShouldReturnApplyClause() { var tokens = _parser.ParseApply("groupby((MyDog/Color, MyDog/Breed))/groupby((MyDog/Color), aggregate(MyDog/Breed with max as MaxBreed))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); var actual = binder.BindApply(tokens); Assert.NotNull(actual); Assert.Equal(2, actual.Transformations.Count()); Assert.IsType <GroupByTransformationNode>(actual.Transformations.Last()); }
public void BindApplyWithMultipleGroupBysShouldReturnApplyClause() { var tokens = _parser.ParseApply("groupby((MyDog/Color, MyDog/Breed))/groupby((MyDog/Color), aggregate(MyDog/Breed with max as MaxBreed))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); var actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(2); var groupBy = actual.Transformations.Last() as GroupByTransformationNode; groupBy.Should().NotBeNull(); }
public void BindApplyWithCountInAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("aggregate($count as TotalCount)"); 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.Expressions); AggregateExpression statement = Assert.Single(aggregate.Expressions); Assert.Equal(AggregationMethod.VirtualPropertyCount, statement.Method); Assert.Equal("TotalCount", statement.Alias); }
public void BindApplyWitGroupByWithAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice), 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(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; TransformationNode aggregate = groupBy.ChildTransformations; aggregate.Should().NotBeNull(); }
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.ChildTransformations; aggregate.Should().NotBeNull(); }
public void BindApplyWitGroupByWithDeepNavigationAndComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/LionWhoAteMe/LionHeartbeat/Frequency))"); 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); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode dogNode = groupingProperties[0]; dogNode.Name.Should().Be("MyDog"); dogNode.Expression.Should().BeNull(); dogNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode lionNode = dogNode.ChildTransformations[0]; lionNode.Name.Should().Be("LionWhoAteMe"); lionNode.Expression.Should().BeNull(); lionNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode heartBeatNode = lionNode.ChildTransformations[0]; heartBeatNode.Name.Should().Be("LionHeartbeat"); heartBeatNode.Expression.Should().BeNull(); heartBeatNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode frequencyNode = heartBeatNode.ChildTransformations[0]; frequencyNode.Name.Should().Be("Frequency"); frequencyNode.Expression.Should().NotBeNull(); frequencyNode.ChildTransformations.Should().BeEmpty(); }
public void BindApplyWithComputeShouldReturnApplyClause() { var tokens = _parser.ParseApply("compute(UnitPrice mul 5 as BigPrice)"); var binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); var actual = binder.BindApply(tokens); Assert.NotNull(actual); ComputeTransformationNode compute = Assert.IsType <ComputeTransformationNode>(Assert.Single(actual.Transformations)); Assert.Equal(TransformationNodeKind.Compute, compute.Kind); Assert.NotNull(compute.Expressions); ComputeExpression statement = Assert.Single(compute.Expressions); VerifyIsFakeSingleValueNode(statement.Expression); Assert.Equal("BigPrice", statement.Alias); }