AggregateExpressionToken

We found 10 examples in language CSharp for this search. You will see 45 fragments of code.

Other methods

Other methods


        [Fact]
        public void ExpressionCannotBeNull()
        {
            Action action = () => new AggregateExpressionToken(null, AggregationMethod.Sum, "Alias");
            Assert.Throws<ArgumentNullException>("expression", action);
        }

        [Fact]
        public void AliasCannotBeNull()
        {
            Action action = () => new AggregateExpressionToken(expressionToken, AggregationMethod.Sum, null);
            Assert.Throws<ArgumentNullException>("alias", action);
        }

        [Fact]
        public void ExpressionSetCorrectly()
        {
            AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.Sum, "Alias");
            Assert.Same(expressionToken, token.Expression);
        }

        [Fact]
        public void WithMethodSetCorrectly()
        {
            AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias");
            Assert.Equal(AggregationMethod.CountDistinct, token.Method);
        }

        [Fact]
        public void AliasSetCorrectly()
        {
            AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias");
            Assert.Equal("Alias", token.Alias);
        }

        [Fact]
        public void KindIsSetCorrectly()
        {
            AggregateExpressionToken token = new AggregateExpressionToken(expressionToken, AggregationMethod.CountDistinct, "Alias");
            Assert.Equal(QueryTokenKind.AggregateExpression, token.Kind);
        }


        /// <summary>
        /// Visits a AggregateExpressionToken
        /// </summary>
        /// <param name="tokenIn">The AggregateExpressionToken to bind</param>
        /// <returns>A T node bound to this AggregateExpressionToken</returns>
        T Visit(AggregateExpressionToken tokenIn);


        /// <summary>
        /// Visits an AggregateExpressionToken
        /// </summary>
        /// <param name="tokenIn">The AggregateExpressionToken to visit</param>
        /// <returns>A T bound to this AggregateExpressionToken</returns>
        public virtual T Visit(AggregateExpressionToken tokenIn)
        {
            throw new NotImplementedException();
        }


        [Fact]
        public void AnyAllSyntacticParsingShouldCheckSeperatorTokenIsColon()
        {
            // Repro for: Syntactic parsing for Any/All allows an arbitrary token between range variable and expression
            Action parse = () => this.testSubject.ParseFilter("Things/any(a,true)");
            parse.Throws<ODataException>(ErrorStrings.ExpressionLexer_SyntaxError("13", "Things/any(a,true)"));
        }

        [Fact]
        public void AnyAllSyntacticParsingShouldNotAllowImplicitRangeVariableToBeRedefined()
        {
            // Repro for: Syntactic parser fails to block $it as a range variable name
            Action parse = () => this.testSubject.ParseFilter("Things/any($it:true)");
            parse.Throws<ODataException>(ErrorStrings.UriQueryExpressionParser_RangeVariableAlreadyDeclared("$it"));
        }

        [Fact]
        public void AnyAllSyntacticParsingShouldNotAllowAnyRangeVariableToBeRedefined()
        {
            // Repro for: Semantic binding fails with useless error message when a range variable is redefined within a nested any/all
            Action parse = () => this.testSubject.ParseFilter("Things/any(o:o/Things/any(o:true))");
            parse.Throws<ODataException>(ErrorStrings.UriQueryExpressionParser_RangeVariableAlreadyDeclared("o"));
        }

        [Fact]
        public void AnyAllSyntacticParsingShouldNotRecognizeRangeVariablesOutsideOfScope()
        {
            // Repro for: Syntactic parser assumes any token which matches the name of a previously used range variable is also a range variable, even after the scope has been exited
            QueryToken tree = this.testSubject.ParseFilter("Things/any(o:true) and o");
            tree.ShouldBeBinaryOperatorQueryToken(BinaryOperatorKind.And).Right.ShouldBeEndPathToken("o");
        }

        [Fact]
        public void TypeNameShouldParseSuccessfully()
        {
            this.testSubject.ParseFilter("fq.ns.typename").ShouldBeDottedIdentifierToken("fq.ns.typename");
        }

        [Fact]
        public void QualifiedFunctionNameShouldParseSuccessfully()
        {
            this.testSubject.ParseFilter("fq.ns.container.function()").ShouldBeFunctionCallToken("fq.ns.container.function");
        }

        #region Select

        [Fact]
        public void SelectTermTokenPathIsSet()
        {
            // Arrange
            PathSegmentToken pathToken = new NonSystemToken("SomeProp", null, null);
            SelectExpandOptionParser optionParser = new SelectExpandOptionParser(5);

            // Act
            SelectTermToken selectTermToken = optionParser.BuildSelectTermToken(pathToken, "");

            // Assert
            Assert.NotNull(selectTermToken);
            Assert.NotNull(selectTermToken.PathToProperty);
            Assert.Equal("SomeProp", selectTermToken.PathToProperty.Identifier);
        }

        [Fact]
        public void AllNestedOptionsAreNullIfNotPresentInSelect()
        {
            // Arrange & Act
            SelectTermToken selectTerm = this.ParseSelectOptions("");

            // Assert
            Assert.NotNull(selectTerm);
            Assert.Null(selectTerm.FilterOption);
            Assert.Null(selectTerm.OrderByOptions);
            Assert.Null(selectTerm.TopOption);
            Assert.Null(selectTerm.SkipOption);
            Assert.Null(selectTerm.CountQueryOption);
            Assert.Null(selectTerm.SearchOption);
            Assert.Null(selectTerm.SelectOption);
        }

        [Theory]
        [InlineData("($filter=true)")]
        [InlineData("($filter=true;)")]
        public void NestedFilterOptionInSelectIsAllowed(string optionsText)
        {
            // Arrange & Act
            SelectTermToken selectTerm = this.ParseSelectOptions(optionsText);

            // Assert
            Assert.NotNull(selectTerm);
            Assert.NotNull(selectTerm.FilterOption);
            selectTerm.FilterOption.ShouldBeLiteralQueryToken(true);
        }

        [Theory]
        [InlineData("($orderby=two)")]
        [InlineData("($orderby=two;)")]
        public void NestedOrderbyInSelectIsAllowed(string optionsText)
        {
            // Arrange & Act
            SelectTermToken selectTerm = this.ParseSelectOptions(optionsText);

            // Assert
            Assert.NotNull(selectTerm);
            Assert.NotNull(selectTerm.OrderByOptions);
            OrderByToken orderBy = Assert.Single(selectTerm.OrderByOptions);
            orderBy.Expression.ShouldBeEndPathToken("two");
        }

        [Theory]
        [InlineData("($top=24)")]
        [InlineData("($top=24;)")]
        public void NestedTopInSelectIsAllowed(string optionsText)
        {
            // Arrange & Act
            SelectTermToken selectTerm = this.ParseSelectOptions(optionsText);

            // Assert
            Assert.NotNull(selectTerm);
            Assert.NotNull(selectTerm.TopOption);
            Assert.Equal(24, selectTerm.TopOption);
        }

        [Theory]
        [InlineData("($skip=42)")]
        [InlineData("($skip=42;)")]
        public void NestedSkipInSelectIsAllowed(string optionsText)
        {
            // Arrange & Act
            SelectTermToken selectTerm = this.ParseSelectOptions(optionsText);

            // Assert
            Assert.NotNull(selectTerm);
            Assert.NotNull(selectTerm.SkipOption);
            Assert.Equal(42, selectTerm.SkipOption);
        }

        /// <summary>
        /// Visit an AllToken
        /// </summary>
        /// <param name="tokenIn">The All token to visit</param>
        /// <returns>An AllNode bound to this token</returns>
         T Visit(AllToken tokenIn);

        /// <summary>
        /// Visits an AnyToken
        /// </summary>
        /// <param name="tokenIn">The Any token to visit</param>
        /// <returns>An AnyNode that's bound to this token</returns>
        T Visit(AnyToken tokenIn);

        /// <summary>
        /// Visits a BinaryOperatorToken
        /// </summary>
        /// <param name="tokenIn">The Binary operator token to visit.</param>
        /// <returns>A BinaryOperatorNode that's bound to this token</returns>
        T Visit(BinaryOperatorToken tokenIn);

        /// <summary>
        /// Visits a CountSegmentToken
        /// </summary>
        /// <param name="tokenIn">The Count segment token to visit.</param>
        /// <returns>A CountNode that's bound to this token</returns>
        T Visit(CountSegmentToken tokenIn);

        /// <summary>
        /// Visits an InToken
        /// </summary>
        /// <param name="tokenIn">The In token to visit.</param>
        /// <returns>An InNode that's bound to this token</returns>
        T Visit(InToken tokenIn);

        /// <summary>
        /// Visits a DottedIdentifierToken
        /// </summary>
        /// <param name="tokenIn">The DottedIdentifierToken to visit</param>
        /// <returns>Either a SingleResourceCastNode, or CollectionResourceCastNode bound to this DottedIdentifierToken</returns>
        T Visit(DottedIdentifierToken tokenIn);

        /// <summary>
        /// Visit an AllToken
        /// </summary>
        /// <param name="tokenIn">The All token to visit</param>
        /// <returns>An AllNode bound to this token</returns>
         T Visit(AllToken tokenIn);

        /// <summary>
        /// Visits an AnyToken
        /// </summary>
        /// <param name="tokenIn">The Any token to visit</param>
        /// <returns>An AnyNode that's bound to this token</returns>
        T Visit(AnyToken tokenIn);

        /// <summary>
        /// Visits a BinaryOperatorToken
        /// </summary>
        /// <param name="tokenIn">The Binary operator token to visit.</param>
        /// <returns>A BinaryOperatorNode that's bound to this token</returns>
        T Visit(BinaryOperatorToken tokenIn);

        /// <summary>
        /// Visits a CountSegmentToken
        /// </summary>
        /// <param name="tokenIn">The Count segment token to visit.</param>
        /// <returns>A CountNode that's bound to this token</returns>
        T Visit(CountSegmentToken tokenIn);

        /// <summary>
        /// Visits an InToken
        /// </summary>
        /// <param name="tokenIn">The In token to visit.</param>
        /// <returns>An InNode that's bound to this token</returns>
        T Visit(InToken tokenIn);

        /// <summary>
        /// Visits a DottedIdentifierToken
        /// </summary>
        /// <param name="tokenIn">The DottedIdentifierToken to visit</param>
        /// <returns>Either a SingleResourceCastNode, or CollectionResourceCastNode bound to this DottedIdentifierToken</returns>
        T Visit(DottedIdentifierToken tokenIn);

        /// <summary>
        /// Visit an AllToken
        /// </summary>
        /// <param name="tokenIn">The All token to visit</param>
        /// <returns>An AllNode bound to this token</returns>
        public virtual T Visit(AllToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits an AnyToken
        /// </summary>
        /// <param name="tokenIn">The Any token to visit</param>
        /// <returns>An AnyNode that's bound to this token</returns>
        public virtual T Visit(AnyToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits a BinaryOperatorToken
        /// </summary>
        /// <param name="tokenIn">The Binary operator token to visit.</param>
        /// <returns>A BinaryOperatorNode that's bound to this token</returns>
        public virtual T Visit(BinaryOperatorToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits a CountSegmentToken
        /// </summary>
        /// <param name="tokenIn">The Count segment token to visit.</param>
        /// <returns>A CountNode that's bound to this token</returns>
        public virtual T Visit(CountSegmentToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits an InToken
        /// </summary>
        /// <param name="tokenIn">The In token to visit.</param>
        /// <returns>An InNode that's bound to this token</returns>
        public virtual T Visit(InToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits a DottedIdentifierToken
        /// </summary>
        /// <param name="tokenIn">The DottedIdentifierToken to visit</param>
        /// <returns>Either a SingleResourceCastNode, or CollectionResourceCastNode bound to this DottedIdentifierToken</returns>
        public virtual T Visit(DottedIdentifierToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visit an AllToken
        /// </summary>
        /// <param name="tokenIn">The All token to visit</param>
        /// <returns>An AllNode bound to this token</returns>
        public virtual T Visit(AllToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits an AnyToken
        /// </summary>
        /// <param name="tokenIn">The Any token to visit</param>
        /// <returns>An AnyNode that's bound to this token</returns>
        public virtual T Visit(AnyToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits a BinaryOperatorToken
        /// </summary>
        /// <param name="tokenIn">The Binary operator token to visit.</param>
        /// <returns>A BinaryOperatorNode that's bound to this token</returns>
        public virtual T Visit(BinaryOperatorToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits a CountSegmentToken
        /// </summary>
        /// <param name="tokenIn">The Count segment token to visit.</param>
        /// <returns>A CountNode that's bound to this token</returns>
        public virtual T Visit(CountSegmentToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits an InToken
        /// </summary>
        /// <param name="tokenIn">The In token to visit.</param>
        /// <returns>An InNode that's bound to this token</returns>
        public virtual T Visit(InToken tokenIn)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Visits a DottedIdentifierToken
        /// </summary>
        /// <param name="tokenIn">The DottedIdentifierToken to visit</param>
        /// <returns>Either a SingleResourceCastNode, or CollectionResourceCastNode bound to this DottedIdentifierToken</returns>
        public virtual T Visit(DottedIdentifierToken tokenIn)
        {
            throw new NotImplementedException();
        }

//---------------------------------------------------------------------
// <copyright file="AggregateTransformationNode.cs" company="Microsoft">
//      Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------

namespace Microsoft.OData.UriParser.Aggregation
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using ODataErrorStrings = Microsoft.OData.Strings;

    /// <summary>
    /// Node representing a aggregate transformation.
    /// </summary>
    public sealed class AggregateTransformationNode : TransformationNode
    {
        private readonly IEnumerable<AggregateExpressionBase> expressions;

        /// <summary>
        /// Create a AggregateTransformationNode.
        /// </summary>
        /// <param name="expressions">A list of <see cref="AggregateExpressionBase"/>.</param>
        public AggregateTransformationNode(IEnumerable<AggregateExpressionBase> expressions)
        {
            ExceptionUtils.CheckArgumentNotNull(expressions, "expressions");

            this.expressions = expressions;
        }

        /// <summary>
        /// Property that only return <see cref="AggregateExpression"/>s.
        /// </summary>
        [Obsolete("Use AggregateExpressions for all aggregation expressions or AggregateExpressions.OfType<AggregateExpressionToken>()  for aggregate(..) expressions only.")]
        public IEnumerable<AggregateExpression> Expressions
        {
            get
            {
                return expressions.OfType<AggregateExpression>();
            }
        }

        /// <summary>
        /// Property that returns a list of all <see cref="AggregateExpressionBase"/>s of this transformation node.
        /// </summary>
        public IEnumerable<AggregateExpressionBase> AggregateExpressions
        {
            get
            {
                return expressions;
            }
        }

        /// <summary>
        /// Gets the kind of the transformation node.
        /// </summary>
        public override TransformationNodeKind Kind
        {
            get
            {
                return TransformationNodeKind.Aggregate;
            }
        }
    }
}

Microsoft.OData.UriParser.Aggregation.AggregateExpressionToken : AggregateTokenBase

Constructors :

public AggregateExpressionToken(QueryToken expression = , AggregationMethod method = , String alias = )
public AggregateExpressionToken(QueryToken expression = , AggregationMethodDefinition methodDefinition = , String alias = )

Methods :

public QueryTokenKind get_Kind()
public AggregationMethod get_Method()
public QueryToken get_Expression()
public AggregationMethodDefinition get_MethodDefinition()
public String get_Alias()
public T Accept(ISyntacticTreeVisitor<T> visitor = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()