Exemple #1
0
        public void NestedComputeAndSelectInExpandIsAllowed()
        {
            // Arrange & Act
            ExpandTermToken expandTerm = this.ParseExpandOptions("($compute=Price mul Qty as TotalPrice;$select=Name,Qty,TotalPrice)");

            // Assert
            Assert.NotNull(expandTerm);
            Assert.NotNull(expandTerm.ComputeOption);
            Assert.NotNull(expandTerm.ComputeOption.Expressions);

            ComputeExpressionToken computeExpressionToken = Assert.Single(expandTerm.ComputeOption.Expressions);

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

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

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

            SelectTermToken[] selectTerms = expandTerm.SelectOption.SelectTerms.ToArray();
            Assert.Equal(3, selectTerms.Length);
            selectTerms[0].PathToProperty.ShouldBeNonSystemToken("Name");
            selectTerms[1].PathToProperty.ShouldBeNonSystemToken("Qty");
            selectTerms[2].PathToProperty.ShouldBeNonSystemToken("TotalPrice");
        }
        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 #3
0
        public void ComputeExpressionNotImplemented()
        {
            ComputeExpressionToken token   = new ComputeExpressionToken(new EndPathToken("Identifier", null), "Id");
            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(ComputeExpressionToken).ToString());
        }
        public void ComputeExpressionNotImplemented()
        {
            ComputeExpressionToken token   = new ComputeExpressionToken(new EndPathToken("Identifier", null), "Id");
            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(ComputeExpressionToken).ToString(), token.Accept <string>(computer));
        }
Exemple #5
0
        public void NestedComputeInExpandIsAllowed(string optionsText)
        {
            // Arrange & Act
            ExpandTermToken expandTerm = this.ParseExpandOptions(optionsText);

            // Assert
            Assert.NotNull(expandTerm);
            Assert.NotNull(expandTerm.ComputeOption);
            Assert.NotNull(expandTerm.ComputeOption.Expressions);
            ComputeExpressionToken computeExpressionToken = Assert.Single(expandTerm.ComputeOption.Expressions);

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

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

            binaryOperatorToken.Left.ShouldBeEndPathToken("Price");
            binaryOperatorToken.Right.ShouldBeEndPathToken("Qty");
        }
        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 #8
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 #9
0
 public override string Visit(ComputeExpressionToken tokenIn)
 {
     return(tokenIn.ToString());
 }
Exemple #10
0
 /// <summary>
 /// Visits a ComputeExpressionToken
 /// </summary>
 /// <param name="tokenIn">The ComputeExpressionToken to bind</param>
 /// <returns>A user defined value</returns>
 public virtual T Visit(ComputeExpressionToken tokenIn)
 {
     throw new NotImplementedException();
 }