public void Test_Not_Method_Call_Expression_Should_Not_Fail()
        {
            // Arrange
            var expression = (Expression<Action<ILogger>>) (l => l.DummyProperty.ToString());
            var parser = new ExpressionsParser();

            // Act
            var expected = parser.Parse(expression);

            // Assert
            Assert.IsNotNull(expected, "Parser should parse property access expressions.");
        }
        public void Test_Non_Dependencies_Method_Call_Should_Not_Fail()
        {
            // Arrange
            var expression = (Expression<Action<ILogger>>) (l => Console.WriteLine("Oops!"));
            var parser = new ExpressionsParser();

            // Act
            var expected = parser.Parse(expression);

            // Assert
            Assert.IsNotNull(expected, "Parser should parse expressions with other calls as well.");
        }
        public void Test_Parse_Returns_Valid_CallExpression()
        {
            // Arrange
            var expression = (Expression<Action<ILogger>>)(l => l.Write(1, 2.0));
            var parser = new ExpressionsParser();

            // Act
            var result = parser.Parse(expression);
            Console.WriteLine("Expression as string: {0}", result.CallExpression);

            // Assert
            Assert.That(result.CallExpression.Contains("l.Write"));
        }
        public void Test_Parse_Two_Arguments()
        {
            // Arrange
            var expression = (Expression<Action<ILogger>>)(l => l.Write(1, 2.0));
            var parser = new ExpressionsParser();

            // Act
            var result = parser.Parse(expression);

            // Assert
            Assert.That(result.Arguments.Length, Is.EqualTo(2));
            Assert.That(result.Arguments[0], Is.EqualTo(new SingleArgumentValue(1)));
            Assert.That(result.Arguments[1], Is.EqualTo(new SingleArgumentValue(2.0)));
        }
        public void Test_Parse_Simple_Expression()
        {
            // Arrange
            var expression = (Expression<Action<ILogger>>)(l => l.Write());
            var parser = new ExpressionsParser();

            // Act
            var result = parser.Parse(expression);

            // Assert
            Assert.That(result.Method.Name, Is.EqualTo("Write"));
            CollectionAssert.IsEmpty(result.Arguments);
            Assert.That(result.Times, Is.EqualTo(Times.Once()));
        }
Exemplo n.º 6
0
        public Dictionary <string, object> GetStringValue(string expression)
        {
            string            returnValue       = null;
            ExpressionsLexer  lexer             = new ExpressionsLexer(new AntlrInputStream(GetCharStream(expression)));
            CommonTokenStream tokenStream       = new CommonTokenStream(lexer);
            ExpressionsParser expressionsParser = new ExpressionsParser(tokenStream);

            ExpressionsParser.ParseContext tree = expressionsParser.parse();

            ParseTreeWalker  walker = new ParseTreeWalker();
            ExpressionLoader loader = new ExpressionLoader();

            walker.Walk(loader, tree);

            var dictionary = loader.GetMap();

            return(dictionary);
        }
            public void Setup()
            {
                // Arrange
                var expression = (Expression<Action<ILogger>>)(l => l.Write());
                var parser = new ExpressionsParser();

                // Act
                _expectedCall = parser.Parse(expression);
            }
        public ArgumentValue Parse_Arguments_For_Func_Expression(Expression<Func<ILogger, int>> expression)
        {
            // Arrange
            var parser = new ExpressionsParser();

            // Act & Assert
            return parser.Parse(expression).Arguments[0];
        }