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"); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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"); }
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"); }
/// <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); }
/// <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; }