Example #1
0
        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();
        }
Example #2
0
        public void BindApplyWithNullShouldThrow()
        {
            ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState);
            Action      bind   = () => binder.BindApply(null);

            Assert.Throws <ArgumentNullException>("tokens", bind);
        }
Example #3
0
        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();
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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));
        }
Example #7
0
        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);
        }
Example #8
0
        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();
        }
Example #9
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);
        }
Example #10
0
        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();
        }
Example #11
0
        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();
        }
Example #12
0
        public void BindApplyWithNullShouldThrow()
        {
            var    binder = new ApplyBinder(FakeBindMethods.BindSingleValueProperty, _bindingState);
            Action bind   = () => binder.BindApply(null);

            bind.ShouldThrow <ArgumentNullException>();
        }
Example #13
0
        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");
        }
Example #14
0
        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");
        }
Example #15
0
        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);
        }
Example #16
0
        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);
        }
Example #17
0
        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]);
        }
Example #18
0
        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();
        }
Example #19
0
        /// <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);
        }
Example #20
0
        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);
        }
Example #21
0
        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();
        }
Example #22
0
        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());
        }
Example #23
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);
        }
Example #24
0
        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();
        }
Example #25
0
        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);
        }
Example #26
0
        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();
        }
Example #27
0
        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();
        }
Example #28
0
        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();
        }
Example #29
0
        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);
        }
Example #30
0
        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);
        }