Exemple #1
0
        public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
        {
            var setup = new SetupConverter(node);

            if (setup.IsSetup)
            {
                return(setup.Replace());
            }

            var testToFact = new TestToFact(node);

            if (testToFact.IsTest)
            {
                node = node.WithAttributeLists(testToFact.Convert(node.AttributeLists));
            }

            var attributeRemover = new AttributeRemover(node.AttributeLists, "TearDown");

            if (attributeRemover.IsHavingAttribute)
            {
                node = node.WithAttributeLists(attributeRemover.Remove());
                node = node.WithIdentifier(SyntaxFactory.Identifier("Dispose"));
            }

            return(base.VisitMethodDeclaration(node));
        }
Exemple #2
0
        public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            var attributeRemover = new AttributeRemover(node.AttributeLists, "TestFixture");

            if (attributeRemover.IsHavingAttribute)
            {
                if (!node.Modifiers.Any(m => m.IsKind(SyntaxKind.PublicKeyword)))
                {
                    var publicKeyword = SyntaxFactory.Token(SyntaxKind.PublicKeyword)
                                        .WithTrailingTrivia(SyntaxTriviaList.Create(SyntaxFactory.Space));
                    node = node.WithModifiers(node.Modifiers.Add(publicKeyword));
                }

                node = node.WithAttributeLists(attributeRemover.Remove());
            }

            if (node.DescendantNodes().Any(n => n is MethodDeclarationSyntax m &&
                                           m.AttributeLists.Contains("TearDown")))
            {
                node = node.AddBaseListTypes(
                    SyntaxFactory.SimpleBaseType(
                        SyntaxFactory.IdentifierName("IDisposable")).WithoutTrivia());
                node = node.WithIdentifier(node.Identifier.WithoutTrivia());
            }

            return(base.VisitClassDeclaration(node));
        }
Exemple #3
0
        public SyntaxList <AttributeListSyntax> Convert(
            SyntaxList <AttributeListSyntax> attributeList)
        {
            var attributeRemover = new AttributeRemover(attributeList, "Ignore");
            var isIgnore         = attributeRemover.IsHavingAttribute;

            var ignoreText = "\"\"";

            if (isIgnore)
            {
                var ignoreAttributes = attributeList.First(a =>
                                                           a.Attributes.Any(at =>
                                                                            at.Name.ToString().Equals("Ignore", StringComparison.OrdinalIgnoreCase)));

                var ignoreAttribute = ignoreAttributes.Attributes.First(at =>
                                                                        at.Name.ToString().Equals("Ignore", StringComparison.OrdinalIgnoreCase));

                if (ignoreAttribute.ArgumentList?.Arguments.Any() ?? false)
                {
                    ignoreText = ignoreAttribute.ArgumentList.Arguments.First().Expression.ToString();
                }

                attributeList = attributeRemover.Remove();
            }

            attributeList = Convert(attributeList, isIgnore, ignoreText);
            return(attributeList);
        }