private AggregationMethodDefinition ParseAggregateWith() { if (!TokenIdentifierIs(ExpressionConstants.KeywordWith)) { throw ParseError(ODataErrorStrings.UriQueryExpressionParser_WithExpected(this.lexer.CurrentToken.Position, this.lexer.ExpressionText)); } lexer.NextToken(); AggregationMethodDefinition verb; int identifierStartPosition = lexer.CurrentToken.Position; string methodLabel = lexer.ReadDottedIdentifier(false /* acceptStar */); switch (methodLabel) { case ExpressionConstants.KeywordAverage: verb = AggregationMethodDefinition.Average; break; case ExpressionConstants.KeywordCountDistinct: verb = AggregationMethodDefinition.CountDistinct; break; case ExpressionConstants.KeywordMax: verb = AggregationMethodDefinition.Max; break; case ExpressionConstants.KeywordMin: verb = AggregationMethodDefinition.Min; break; case ExpressionConstants.KeywordSum: verb = AggregationMethodDefinition.Sum; break; default: if (!methodLabel.Contains(OData.ExpressionConstants.SymbolDot)) { throw ParseError( ODataErrorStrings.UriQueryExpressionParser_UnrecognizedWithMethod( methodLabel, identifierStartPosition, this.lexer.ExpressionText)); } verb = AggregationMethodDefinition.Custom(methodLabel); break; } return(verb); }
public void ParseApplyWithDottedUnkownExpressionShouldReturnCustomAggregateToken() { string apply = "aggregate(UnitPrice with Custom.Aggregate as CustomAggregate)"; IEnumerable <QueryToken> actual = this.testSubject.ParseApply(apply); actual.Should().NotBeNull(); actual.Should().HaveCount(1); AggregateToken aggregate = actual.First() as AggregateToken; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); VerifyAggregateExpressionToken("UnitPrice", AggregationMethodDefinition.Custom("Custom.Aggregate"), "CustomAggregate", aggregate.AggregateExpressions.First() as AggregateExpressionToken); }