Ejemplo n.º 1
0
        public void NestedGroupbyTransformationsIsAllowed()
        {
            var result = this.ParseExpandOptions("($apply=groupby((Customer/CountryRegion,Product/Name),aggregate(Amount with sum as Total)))");

            result.Should().NotBeNull();

            QueryToken token = result.ApplyOptions.Single();

            token.Should().BeOfType <GroupByToken>();
            GroupByToken groupBy = token as GroupByToken;

            groupBy.Properties.Should().HaveCount(2);
            QueryToken   queryToken = groupBy.Properties.ElementAt(0);
            EndPathToken pathToken  = queryToken.ShouldBeEndPathToken("CountryRegion");

            pathToken.NextToken.ShouldBeInnerPathToken("Customer");

            queryToken = groupBy.Properties.ElementAt(1);
            pathToken  = queryToken.ShouldBeEndPathToken("Name");
            pathToken.NextToken.ShouldBeInnerPathToken("Product");

            groupBy.Child.Should().NotBeNull();
            groupBy.Child.Should().BeOfType <AggregateToken>();
            AggregateToken           aggregate = groupBy.Child as AggregateToken;
            AggregateExpressionToken aggregateExpressionToken = aggregate.Expressions.Single();

            aggregateExpressionToken.Alias.Should().Equals("Total");
            aggregateExpressionToken.Method.Should().Equals(AggregationMethod.Sum);
            aggregateExpressionToken.Expression.ShouldBeEndPathToken("Amount");
        }
Ejemplo n.º 2
0
        public static AndConstraint <StringLiteralToken> ShouldBeStringLiteralToken(this QueryToken token, string text)
        {
            token.Should().BeOfType <StringLiteralToken>();
            StringLiteralToken stringLiteralToken = token.As <StringLiteralToken>();

            stringLiteralToken.Text.Should().Be(text);
            return(new AndConstraint <StringLiteralToken>(stringLiteralToken));
        }
Ejemplo n.º 3
0
        public static AndConstraint <StarToken> ShouldBeStarToken(this QueryToken token)
        {
            token.Should().BeOfType <StarToken>();
            var starToken = token.As <StarToken>();

            starToken.Kind.Should().Be(QueryTokenKind.Star);
            return(new AndConstraint <StarToken>(starToken));
        }
Ejemplo n.º 4
0
        public static AndConstraint <AllToken> ShouldBeAllToken(this QueryToken token, string expectedParameterName)
        {
            token.Should().BeOfType <AllToken>();
            var allToken = token.As <AllToken>();

            allToken.Kind.Should().Be(QueryTokenKind.Any);
            allToken.Parameter.Should().Be(expectedParameterName);
            return(new AndConstraint <AllToken>(allToken));
        }
Ejemplo n.º 5
0
        public static AndConstraint <EndPathToken> ShouldBeEndPathToken(this QueryToken token, string expectedName)
        {
            token.Should().BeOfType <EndPathToken>();
            var propertyAccessQueryToken = token.As <EndPathToken>();

            propertyAccessQueryToken.Kind.Should().Be(QueryTokenKind.EndPath);
            propertyAccessQueryToken.Identifier.Should().Be(expectedName);
            return(new AndConstraint <EndPathToken>(propertyAccessQueryToken));
        }
Ejemplo n.º 6
0
        public static AndConstraint <DottedIdentifierToken> ShouldBeDottedIdentifierToken(this QueryToken token, string typeName)
        {
            token.Should().BeOfType <DottedIdentifierToken>();
            var dottedIdentifierToken = token.As <DottedIdentifierToken>();

            dottedIdentifierToken.Kind.Should().Be(QueryTokenKind.DottedIdentifier);
            dottedIdentifierToken.Identifier.Should().Be(typeName);
            return(new AndConstraint <DottedIdentifierToken>(dottedIdentifierToken));
        }
Ejemplo n.º 7
0
        public static AndConstraint <LiteralToken> ShouldBeLiteralQueryToken(this QueryToken token, object expectedValue)
        {
            token.Should().BeOfType <LiteralToken>();
            var literalToken = token.As <LiteralToken>();

            literalToken.Kind.Should().Be(QueryTokenKind.Literal);
            literalToken.Value.Should().Be(expectedValue);
            return(new AndConstraint <LiteralToken>(literalToken));
        }
Ejemplo n.º 8
0
        public static AndConstraint <RangeVariableToken> ShouldBeRangeVariableToken(this QueryToken token, string expectedName)
        {
            token.Should().BeOfType <RangeVariableToken>();
            var parameterQueryToken = token.As <RangeVariableToken>();

            parameterQueryToken.Kind.Should().Be(QueryTokenKind.RangeVariable);
            parameterQueryToken.Name.Should().Be(expectedName);
            return(new AndConstraint <RangeVariableToken>(parameterQueryToken));
        }
Ejemplo n.º 9
0
        public static AndConstraint <UnaryOperatorToken> ShouldBeUnaryOperatorQueryToken(this QueryToken token, UnaryOperatorKind expectedOperatorKind)
        {
            token.Should().BeOfType <UnaryOperatorToken>();
            var propertyAccessQueryToken = token.As <UnaryOperatorToken>();

            propertyAccessQueryToken.Kind.Should().Be(QueryTokenKind.UnaryOperator);
            propertyAccessQueryToken.OperatorKind.Should().Be(expectedOperatorKind);
            return(new AndConstraint <UnaryOperatorToken>(propertyAccessQueryToken));
        }
Ejemplo n.º 10
0
        public static AndConstraint <FunctionCallToken> ShouldBeFunctionCallToken(this QueryToken token, string name)
        {
            token.Should().BeOfType <FunctionCallToken>();
            var functionCallQueryToken = token.As <FunctionCallToken>();

            functionCallQueryToken.Kind.Should().Be(QueryTokenKind.FunctionCall);
            functionCallQueryToken.Name.Should().Be(name);
            return(new AndConstraint <FunctionCallToken>(functionCallQueryToken));
        }
Ejemplo n.º 11
0
        public static AndConstraint <InnerPathToken> ShouldBeInnerPathToken(this QueryToken token, string expectedName)
        {
            token.Should().BeOfType <InnerPathToken>();
            var nonRootToken = token.As <InnerPathToken>();

            nonRootToken.Kind.Should().Be(QueryTokenKind.InnerPath);
            nonRootToken.Identifier.Should().Be(expectedName);
            return(new AndConstraint <InnerPathToken>(nonRootToken));
        }
Ejemplo n.º 12
0
        public static AndConstraint <SelectToken> ShouldBeSelectToken(this QueryToken token, string[] propertyNames)
        {
            token.Should().BeOfType <SelectToken>();
            SelectToken selectToken = token as SelectToken;

            if (propertyNames.Any())
            {
                selectToken.Properties.Should().HaveSameCount(propertyNames);
                selectToken.Properties.Should().OnlyContain(x => propertyNames.Contains(x.Identifier));
            }
            return(new AndConstraint <SelectToken>(selectToken));
        }
Ejemplo n.º 13
0
        public static AndConstraint <ExpandTermToken> ShouldBeExpandTermToken(this QueryToken token, string propertyName, bool checkNullParent)
        {
            token.Should().BeOfType <ExpandTermToken>();
            ExpandTermToken expandTermToken = token.As <ExpandTermToken>();

            expandTermToken.Kind.Should().Be(QueryTokenKind.ExpandTerm);
            expandTermToken.PathToNavProp.Identifier.Should().Be(propertyName);
            if (checkNullParent)
            {
                expandTermToken.PathToNavProp.NextToken.Should().BeNull();
            }
            return(new AndConstraint <ExpandTermToken>(expandTermToken));
        }
Ejemplo n.º 14
0
        public void NestedAggregateTransformationIsAllowed()
        {
            var result = this.ParseExpandOptions("($apply=aggregate(Amount with sum as Total))");

            result.Should().NotBeNull();

            QueryToken token = result.ApplyOptions.Single();

            token.Should().BeOfType <AggregateToken>();
            AggregateToken           aggregate = token as AggregateToken;
            AggregateExpressionToken aggregateExpressionToken = aggregate.Expressions.Single();

            aggregateExpressionToken.Alias.Should().Equals("Total");
            aggregateExpressionToken.Method.Should().Equals(AggregationMethod.Sum);
            aggregateExpressionToken.Expression.ShouldBeEndPathToken("Amount");
        }
Ejemplo n.º 15
0
        public void NestedComputeTransformationIsAllowed()
        {
            var result = this.ParseExpandOptions("($apply=compute(Amount mul Product/TaxRate as Tax))");

            result.Should().NotBeNull();

            QueryToken token = result.ApplyOptions.Single();

            token.Should().BeOfType <ComputeToken>();
            ComputeToken           compute = token as ComputeToken;
            ComputeExpressionToken computeExpressionToken = compute.Expressions.Single();

            computeExpressionToken.Alias.Should().Equals("Tax");
            BinaryOperatorToken binaryOperatorToken = computeExpressionToken.Expression.ShouldBeBinaryOperatorQueryToken(BinaryOperatorKind.Multiply);

            binaryOperatorToken.Left.ShouldBeEndPathToken("Amount");
            EndPathToken right = binaryOperatorToken.Right.ShouldBeEndPathToken("TaxRate");

            right.NextToken.Should().NotBeNull();
            right.NextToken.ShouldBeInnerPathToken("Product");
        }
Ejemplo n.º 16
0
 /// <summary>
 /// We substitute this method for the MetadataBinder.Bind method to keep the tests from growing too large in scope.
 /// In practice this does the same thing.
 /// </summary>
 internal SingleValueNode BindMethod(QueryToken queryToken)
 {
     queryToken.Should().BeOfType <RangeVariableToken>();
     return(RangeVariableBinder.BindRangeVariableToken(queryToken.As <RangeVariableToken>(), this.bindingState) as SingleValueNode);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// We substitute this method for the MetadataBinder.Bind method to keep the tests from growing too large in scope.
 /// In practice this does the same thing.
 /// </summary>
 internal SingleValueNode BindMethod(QueryToken queryToken)
 {
     queryToken.Should().BeOfType<RangeVariableToken>();
     return RangeVariableBinder.BindRangeVariableToken(queryToken.As<RangeVariableToken>(), this.bindingState) as SingleValueNode;
 }