Beispiel #1
0
        public void ConstructorWithVariableDeclarations()
        {
            string source = @"
                class Class1 {
                    public Class1() {
                        string var1;
                        int var2;
                    }
                }
            ";

            // Getting the AST node
            CSharpSyntaxTree tree = ASTExtractor.Extract(source);

            SyntaxNode node = new NodeLocator(tree).LocateLast(typeof(ConstructorDeclarationSyntax));
            ConstructorDeclarationSyntax constructorDeclarationNode = node as ConstructorDeclarationSyntax;

            // Creating the walker
            var astWalker = MockedConstructorASTWalker.Create(constructorDeclarationNode);

            // Getting the translation unit
            astWalker.Walk();

            // Checking
            Assert.IsNotNull(astWalker.ConstructorDeclaration);

            // Checking members
            Assert.IsNotNull(astWalker.ConstructorDeclaration.Statements);
            Assert.IsTrue(astWalker.ConstructorDeclaration.Statements.Count() > 0);
            Assert.AreEqual(2, astWalker.ConstructorDeclaration.Statements.Count());

            Assert.IsInstanceOfType(astWalker.ConstructorDeclaration.Statements.ElementAt(0), typeof(StatementTranslationUnit));
            Assert.IsInstanceOfType(astWalker.ConstructorDeclaration.Statements.ElementAt(1), typeof(StatementTranslationUnit));
        }
Beispiel #2
0
        public void EmptyMethodWithNoParameters()
        {
            string source = @"
                class Class1 {
                    public Class1() { }
                }
            ";

            // Getting the AST node
            CSharpSyntaxTree tree = ASTExtractor.Extract(source);

            SyntaxNode node = new NodeLocator(tree).LocateLast(typeof(ConstructorDeclarationSyntax));
            ConstructorDeclarationSyntax constructorDeclarationNode = node as ConstructorDeclarationSyntax;

            // Creating the walker
            var astWalker = MockedConstructorASTWalker.Create(constructorDeclarationNode);

            // Getting the translation unit
            astWalker.Walk();

            // Checking
            Assert.IsNotNull(astWalker.ConstructorDeclaration);

            // Checking members
            Assert.IsNotNull(astWalker.ConstructorDeclaration.Arguments);
            Assert.AreEqual(0, astWalker.ConstructorDeclaration.Arguments.Count());
        }
Beispiel #3
0
        public void EmptyMethodWith3Parameters()
        {
            string source = @"
                class Class1 {
                    public Class1(string param1, int param2, bool param3) { }
                }
            ";

            // Getting the AST node
            CSharpSyntaxTree tree = ASTExtractor.Extract(source);

            SyntaxNode node = new NodeLocator(tree).LocateLast(typeof(ConstructorDeclarationSyntax));
            ConstructorDeclarationSyntax constructorDeclarationNode = node as ConstructorDeclarationSyntax;

            // Creating the walker
            var astWalker = MockedConstructorASTWalker.Create(constructorDeclarationNode);

            // Getting the translation unit
            astWalker.Walk();

            // Checking
            Assert.IsNotNull(astWalker.ConstructorDeclaration);

            // Checking members
            Assert.IsNotNull(astWalker.ConstructorDeclaration.Arguments);
            Assert.IsTrue(astWalker.ConstructorDeclaration.Arguments.Count() > 0);
            Assert.AreEqual(3, astWalker.ConstructorDeclaration.Arguments.Count());

            Assert.IsInstanceOfType(astWalker.ConstructorDeclaration.Arguments.ElementAt(0), typeof(ArgumentDefinitionTranslationUnit));
            Assert.IsInstanceOfType(astWalker.ConstructorDeclaration.Arguments.ElementAt(1), typeof(ArgumentDefinitionTranslationUnit));
            Assert.IsInstanceOfType(astWalker.ConstructorDeclaration.Arguments.ElementAt(2), typeof(ArgumentDefinitionTranslationUnit));
        }