Exemple #1
0
        /// <summary>
        /// Create an expand term token
        /// </summary>
        /// <param name="pathToNavigationProp">the nav prop for this expand term</param>
        /// <param name="filterOption">the filter option for this expand term</param>
        /// <param name="orderByOptions">the orderby options for this expand term</param>
        /// <param name="topOption">the top option for this expand term</param>
        /// <param name="skipOption">the skip option for this expand term</param>
        /// <param name="countQueryOption">the query count option for this expand term</param>
        /// <param name="levelsOption">the levels option for this expand term</param>
        /// <param name="searchOption">the search option for this expand term</param>
        /// <param name="selectOption">the select option for this expand term</param>
        /// <param name="expandOption">the expand option for this expand term</param>
        /// <param name="computeOption">the compute option for this expand term.</param>
        public ExpandTermToken(
            PathSegmentToken pathToNavigationProp,
            QueryToken filterOption,
            IEnumerable <OrderByToken> orderByOptions,
            long?topOption,
            long?skipOption,
            bool?countQueryOption,
            long?levelsOption,
            QueryToken searchOption,
            SelectToken selectOption,
            ExpandToken expandOption,
            ComputeToken computeOption)
        {
            ExceptionUtils.CheckArgumentNotNull(pathToNavigationProp, "property");

            this.pathToNavigationProp = pathToNavigationProp;
            this.filterOption         = filterOption;
            this.orderByOptions       = orderByOptions;
            this.topOption            = topOption;
            this.skipOption           = skipOption;
            this.countQueryOption     = countQueryOption;
            this.levelsOption         = levelsOption;
            this.searchOption         = searchOption;
            this.selectOption         = selectOption;
            this.computeOption        = computeOption;
            this.expandOption         = expandOption;
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of  <see cref="SelectExpandTermToken"/> class.
        /// </summary>
        /// <param name="pathToProperty">the path to property for this select or expand term</param>
        /// <param name="filterOption">the filter option for this select or expand term</param>
        /// <param name="orderByOptions">the orderby options for this select or expand term</param>
        /// <param name="topOption">the top option for this select or expand term</param>
        /// <param name="skipOption">the skip option for this select or expand term</param>
        /// <param name="countQueryOption">the query count option for this select or expand term</param>
        /// <param name="searchOption">the search option for this select or expand term</param>
        /// <param name="selectOption">the select option for this select or expand term</param>
        /// <param name="expandOption">the expand option for this select or expand term</param>
        /// <param name="computeOption">the compute option for this select or expand term.</param>
        protected SelectExpandTermToken(
            PathSegmentToken pathToProperty,
            QueryToken filterOption,
            IEnumerable <OrderByToken> orderByOptions,
            long?topOption,
            long?skipOption,
            bool?countQueryOption,
            QueryToken searchOption,
            SelectToken selectOption,
            ExpandToken expandOption,
            ComputeToken computeOption)
        {
            ExceptionUtils.CheckArgumentNotNull(pathToProperty, "property");

            PathToProperty   = pathToProperty;
            FilterOption     = filterOption;
            OrderByOptions   = orderByOptions;
            TopOption        = topOption;
            SkipOption       = skipOption;
            CountQueryOption = countQueryOption;
            SearchOption     = searchOption;
            SelectOption     = selectOption;
            ExpandOption     = expandOption;
            ComputeOption    = computeOption;
        }
        public void NestedComputeAndSelectIsAllowed()
        {
            var result = this.ParseExpandOptions("($compute=Price mul Qty as TotalPrice;$select=Name,Qty,TotalPrice)");

            result.Should().NotBeNull();

            ComputeToken compute = result.ComputeOption;

            compute.Should().NotBeNull();
            compute.Expressions.Should().NotBeNull();
            compute.Expressions.Should().HaveCount(1);

            ComputeExpressionToken computeExpressionToken = result.ComputeOption.Expressions.Single();

            computeExpressionToken.Alias.Should().Equals("TotalPrice");

            BinaryOperatorToken binaryOperatorToken = computeExpressionToken.Expression.ShouldBeBinaryOperatorQueryToken(BinaryOperatorKind.Multiply);

            binaryOperatorToken.Left.ShouldBeEndPathToken("Price");
            binaryOperatorToken.Right.ShouldBeEndPathToken("Qty");

            IEnumerable <PathSegmentToken> selectTerms = result.SelectOption.Properties;

            selectTerms.Should().HaveCount(3);
            selectTerms.ElementAt(0).ShouldBeNonSystemToken("Name");
            selectTerms.ElementAt(1).ShouldBeNonSystemToken("Qty");
            selectTerms.ElementAt(2).ShouldBeNonSystemToken("TotalPrice");
        }
Exemple #4
0
        public void ParseComputeWithMathematicalOperations()
        {
            string       compute = "Prop1 mul Prop2 as Product,Prop1 div Prop2 as Ratio,Prop2 mod Prop2 as Remainder";
            ComputeToken token   = this.testSubject.ParseCompute(compute);

            Assert.Equal(QueryTokenKind.Compute, token.Kind);
            List <ComputeExpressionToken> tokens = token.Expressions.ToList();

            Assert.Equal(3, tokens.Count);
            Assert.Equal(QueryTokenKind.ComputeExpression, tokens[0].Kind);
            Assert.Equal(QueryTokenKind.ComputeExpression, tokens[1].Kind);
            Assert.Equal(QueryTokenKind.ComputeExpression, tokens[2].Kind);
            Assert.Equal("Product", tokens[0].Alias);
            Assert.Equal("Ratio", tokens[1].Alias);
            Assert.Equal("Remainder", tokens[2].Alias);
            Assert.Equal(BinaryOperatorKind.Multiply, (tokens[0].Expression as BinaryOperatorToken).OperatorKind);
            Assert.Equal(BinaryOperatorKind.Divide, (tokens[1].Expression as BinaryOperatorToken).OperatorKind);
            Assert.Equal(BinaryOperatorKind.Modulo, (tokens[2].Expression as BinaryOperatorToken).OperatorKind);

            Action accept1 = () => tokens[0].Accept <ComputeExpression>(null);

            Assert.Throws <NotImplementedException>(accept1);
            Action accept2 = () => token.Accept <ComputeExpression>(null);

            Assert.Throws <NotImplementedException>(accept2);
        }
        public void ParseComputeWithMathematicalOperations()
        {
            string       compute = "Prop1 mul Prop2 as Product,Prop1 div Prop2 as Ratio,Prop2 mod Prop2 as Remainder";
            ComputeToken token   = this.testSubject.ParseCompute(compute);

            token.Kind.ShouldBeEquivalentTo(QueryTokenKind.Compute);
            List <ComputeExpressionToken> tokens = token.Expressions.ToList();

            tokens.Count.Should().Be(3);
            tokens[0].Kind.ShouldBeEquivalentTo(QueryTokenKind.ComputeExpression);
            tokens[1].Kind.ShouldBeEquivalentTo(QueryTokenKind.ComputeExpression);
            tokens[2].Kind.ShouldBeEquivalentTo(QueryTokenKind.ComputeExpression);
            tokens[0].Alias.ShouldBeEquivalentTo("Product");
            tokens[1].Alias.ShouldBeEquivalentTo("Ratio");
            tokens[2].Alias.ShouldBeEquivalentTo("Remainder");
            (tokens[0].Expression as BinaryOperatorToken).OperatorKind.ShouldBeEquivalentTo(BinaryOperatorKind.Multiply);
            (tokens[1].Expression as BinaryOperatorToken).OperatorKind.ShouldBeEquivalentTo(BinaryOperatorKind.Divide);
            (tokens[2].Expression as BinaryOperatorToken).OperatorKind.ShouldBeEquivalentTo(BinaryOperatorKind.Modulo);

            Action accept1 = () => tokens[0].Accept <ComputeExpression>(null);

            accept1.ShouldThrow <NotImplementedException>();
            Action accept2 = () => token.Accept <ComputeExpression>(null);

            accept2.ShouldThrow <NotImplementedException>();
        }
        private ComputeTransformationNode BindComputeToken(ComputeToken token)
        {
            var statements = new List <ComputeExpression>();

            foreach (ComputeExpressionToken statementToken in token.Expressions)
            {
                var singleValueNode = (SingleValueNode)bindMethod(statementToken.Expression);
                statements.Add(new ComputeExpression(singleValueNode, statementToken.Alias, singleValueNode.TypeReference));
            }
            return(new ComputeTransformationNode(statements));
        }
Exemple #7
0
 /// <summary>
 /// Create an expand term token
 /// </summary>
 /// <param name="pathToNavigationProp">the nav prop for this expand term</param>
 /// <param name="filterOption">the filter option for this expand term</param>
 /// <param name="orderByOptions">the orderby options for this expand term</param>
 /// <param name="topOption">the top option for this expand term</param>
 /// <param name="skipOption">the skip option for this expand term</param>
 /// <param name="countQueryOption">the query count option for this expand term</param>
 /// <param name="levelsOption">the levels option for this expand term</param>
 /// <param name="searchOption">the search option for this expand term</param>
 /// <param name="selectOption">the select option for this expand term</param>
 /// <param name="expandOption">the expand option for this expand term</param>
 /// <param name="computeOption">the compute option for this expand term.</param>
 public ExpandTermToken(
     PathSegmentToken pathToNavigationProp,
     QueryToken filterOption,
     IEnumerable <OrderByToken> orderByOptions,
     long?topOption,
     long?skipOption,
     bool?countQueryOption,
     long?levelsOption,
     QueryToken searchOption,
     SelectToken selectOption,
     ExpandToken expandOption,
     ComputeToken computeOption)
     : this(pathToNavigationProp, filterOption, orderByOptions, topOption, skipOption, countQueryOption, levelsOption, searchOption, selectOption, expandOption, computeOption, null)
 {
 }
Exemple #8
0
        public void ComputeNotImplemented()
        {
            ComputeToken token   = new ComputeToken(new List <ComputeExpressionToken>());
            FakeVisitor  visitor = new FakeVisitor();
            Action       visitUnaryOperatorToken = () => visitor.Visit(token);

            visitUnaryOperatorToken.ShouldThrow <NotImplementedException>();
            Action acceptToken = () => token.Accept <string>(visitor);

            acceptToken.ShouldThrow <NotImplementedException>();

            ComputeVisitor computer = new ComputeVisitor();

            token.Accept <string>(computer).ShouldBeEquivalentTo(typeof(ComputeToken).ToString());
        }
        public void ComputeNotImplemented()
        {
            ComputeToken token   = new ComputeToken(new List <ComputeExpressionToken>());
            FakeVisitor  visitor = new FakeVisitor();
            Action       visitUnaryOperatorToken = () => visitor.Visit(token);

            Assert.Throws <NotImplementedException>(visitUnaryOperatorToken);
            Action acceptToken = () => token.Accept <string>(visitor);

            Assert.Throws <NotImplementedException>(acceptToken);

            ComputeVisitor computer = new ComputeVisitor();

            Assert.Equal(typeof(ComputeToken).ToString(), token.Accept <string>(computer));
        }
        public void ComputeSetCorrectly()
        {
            ComputeToken    compute    = new ComputeToken(new ComputeExpressionToken[] { });
            ExpandTermToken expandTerm = new ExpandTermToken(new NonSystemToken("stuff", null, null),
                                                             null /*filterOption*/,
                                                             null /*orderByOption*/,
                                                             null /*topOption*/,
                                                             null /*skipOption*/,
                                                             null /*countQueryOption*/,
                                                             null /*levelsOption*/,
                                                             null /*searchOption*/,
                                                             null /*selectOption*/,
                                                             null /*expandOption*/,
                                                             compute);

            expandTerm.ComputeOption.Should().BeSameAs(compute);
        }
Exemple #11
0
        public void InnerComputeSetCorrectly()
        {
            // Arrange & Act
            ComputeToken    compute    = new ComputeToken(new ComputeExpressionToken[] { });
            SelectTermToken selectTerm = new SelectTermToken(new NonSystemToken("stuff", null, null),
                                                             null /*filterOption*/,
                                                             null /*orderByOption*/,
                                                             null /*topOption*/,
                                                             null /*skipOption*/,
                                                             null /*countQueryOption*/,
                                                             null /*searchOption*/,
                                                             null /*selectOption*/,
                                                             compute);

            // Assert
            Assert.NotNull(selectTerm.ComputeOption);
            Assert.Same(compute, selectTerm.ComputeOption);
        }
Exemple #12
0
 /// <summary>
 /// Create an expand term token
 /// </summary>
 /// <param name="pathToNavigationProp">the nav prop for this expand term</param>
 /// <param name="filterOption">the filter option for this expand term</param>
 /// <param name="orderByOptions">the orderby options for this expand term</param>
 /// <param name="topOption">the top option for this expand term</param>
 /// <param name="skipOption">the skip option for this expand term</param>
 /// <param name="countQueryOption">the query count option for this expand term</param>
 /// <param name="levelsOption">the levels option for this expand term</param>
 /// <param name="searchOption">the search option for this expand term</param>
 /// <param name="selectOption">the select option for this expand term</param>
 /// <param name="expandOption">the expand option for this expand term</param>
 /// <param name="computeOption">the compute option for this expand term.</param>
 /// <param name="applyOptions">the apply options for this expand term.</param>
 public ExpandTermToken(
     PathSegmentToken pathToNavigationProp,
     QueryToken filterOption,
     IEnumerable <OrderByToken> orderByOptions,
     long?topOption,
     long?skipOption,
     bool?countQueryOption,
     long?levelsOption,
     QueryToken searchOption,
     SelectToken selectOption,
     ExpandToken expandOption,
     ComputeToken computeOption,
     IEnumerable <QueryToken> applyOptions)
     : base(pathToNavigationProp, filterOption, orderByOptions, topOption, skipOption, countQueryOption, searchOption, selectOption, computeOption)
 {
     ExpandOption = expandOption;
     LevelsOption = levelsOption;
     ApplyOptions = applyOptions;
 }
Exemple #13
0
        public void ComputeSetCorrectly()
        {
            // Arrange & Act
            ComputeToken    compute    = new ComputeToken(new ComputeExpressionToken[] { });
            ExpandTermToken expandTerm = new ExpandTermToken(new NonSystemToken("stuff", null, null),
                                                             null /*filterOption*/,
                                                             null /*orderByOption*/,
                                                             null /*topOption*/,
                                                             null /*skipOption*/,
                                                             null /*countQueryOption*/,
                                                             null /*levelsOption*/,
                                                             null /*searchOption*/,
                                                             null /*selectOption*/,
                                                             null /*expandOption*/,
                                                             compute);

            // Assert
            Assert.Same(expandTerm.ComputeOption, compute);
        }
        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");
        }
        public void NestedComputeIsAllowed()
        {
            var result = this.ParseExpandOptions("($compute=Price mul Qty as TotalPrice)");

            result.Should().NotBeNull();

            ComputeToken compute = result.ComputeOption;

            compute.Should().NotBeNull();
            compute.Expressions.Should().NotBeNull();
            compute.Expressions.Should().HaveCount(1);

            ComputeExpressionToken computeExpressionToken = result.ComputeOption.Expressions.Single();

            computeExpressionToken.Alias.Should().Equals("TotalPrice");

            BinaryOperatorToken binaryOperatorToken = computeExpressionToken.Expression.ShouldBeBinaryOperatorQueryToken(BinaryOperatorKind.Multiply);

            binaryOperatorToken.Left.ShouldBeEndPathToken("Price");
            binaryOperatorToken.Right.ShouldBeEndPathToken("Qty");
        }
Exemple #16
0
        public void NestedComputeTransformationInExpandIsAllowed()
        {
            // Arrange & Act
            ExpandTermToken expandTerm = this.ParseExpandOptions("($apply=compute(Amount mul Product/TaxRate as Tax))");

            // Assert
            Assert.NotNull(expandTerm);
            Assert.NotNull(expandTerm.ApplyOptions);

            QueryToken   token   = Assert.Single(expandTerm.ApplyOptions);
            ComputeToken compute = Assert.IsType <ComputeToken>(token);

            ComputeExpressionToken computeExpressionToken = Assert.Single(compute.Expressions);

            Assert.Equal("Tax", computeExpressionToken.Alias);

            BinaryOperatorToken binaryOperatorToken = computeExpressionToken.Expression.ShouldBeBinaryOperatorQueryToken(BinaryOperatorKind.Multiply);

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

            Assert.NotNull(right.NextToken);
            right.NextToken.ShouldBeInnerPathToken("Product");
        }
Exemple #17
0
 public override string Visit(ComputeToken tokenIn)
 {
     return(tokenIn.ToString());
 }
 /// <summary>
 /// Create a select term using only the property and its supporting query options.
 /// </summary>
 /// <param name="pathToProperty">the path to the property for this select term</param>
 /// <param name="filterOption">the filter option for this select term</param>
 /// <param name="orderByOptions">the orderby options for this select term</param>
 /// <param name="topOption">the top option for this select term</param>
 /// <param name="skipOption">the skip option for this select term</param>
 /// <param name="countQueryOption">the query count option for this select term</param>
 /// <param name="searchOption">the search option for this select term</param>
 /// <param name="selectOption">the select option for this select term</param>
 /// <param name="computeOption">the compute option for this select term</param>
 public SelectTermToken(PathSegmentToken pathToProperty,
                        QueryToken filterOption, IEnumerable <OrderByToken> orderByOptions, long?topOption, long?skipOption, bool?countQueryOption, QueryToken searchOption, SelectToken selectOption, ComputeToken computeOption)
     : base(pathToProperty, filterOption, orderByOptions, topOption, skipOption, countQueryOption, searchOption, selectOption, computeOption)
 {
 }
Exemple #19
0
 /// <summary>
 /// Visits a ComputeToken
 /// </summary>
 /// <param name="tokenIn">The ComputeToken to bind</param>
 /// <returns>A user defined value</returns>
 public virtual T Visit(ComputeToken tokenIn)
 {
     throw new NotImplementedException();
 }