Beispiel #1
0
        protected override ISyntaxConverter CreateConverter(AttributeSyntax node)
        {
            if (node.Name?.ToString() != "TestCase")
            {
                return(null);
            }

            if (!(node.Parent?.Parent is MethodDeclarationSyntax))
            {
                return(null);
            }

            var result = new TriviaWhitespace.Link(
                new ConstantConverter(AttributeSyntaxFactory.InlineData(node.ArgumentList)),
                node);

            return(result);
        }
Beispiel #2
0
        protected override ISyntaxConverter CreateConverter(AttributeSyntax node)
        {
            if (node.Name?.ToString() != "Category")
            {
                return(null);
            }

            var categoryName = node.ArgumentList?.Arguments.FirstOrDefault().Expression;

            if (categoryName == null)
            {
                return(null);
            }

            var result = new TriviaWhitespace.Link(
                new ConstantConverter(AttributeSyntaxFactory.Category(categoryName)),
                node);

            return(result);
        }
Beispiel #3
0
        public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
        {
            var result = node;

            var attributes = node
                             .AttributeLists
                             .SelectMany(q => q.Attributes)
                             .ToArray();

            // todo aggregate to avoid the enumeration twice

            if (attributes.Any(s => s.Name.ToString() == "TestCase") && attributes.All(s => s.Name.ToString() != "Theory"))
            {
                var theoryList = AttributeSyntaxFactory
                                 .List(AttributeSyntaxFactory.Theory())
                                 .NormalizeWhitespace()
                                 .WithTriviaFrom(node.AttributeLists[0]);

                var attrList = node.AttributeLists
                               .Insert(0, theoryList);

                result = MethodDeclaration(
                    attrList,
                    node.Modifiers,
                    node.ReturnType,
                    node.ExplicitInterfaceSpecifier,
                    node.Identifier,
                    node.TypeParameterList,
                    node.ParameterList,
                    node.ConstraintClauses,
                    node.Body,
                    node.ExpressionBody,
                    node.SemicolonToken);
            }

            return(base.VisitMethodDeclaration(result));
        }