Exemple #1
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 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>();
        }
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);
        }