Exemple #1
0
        public static List <BaseTypeDeclarationSyntax> DoParseFile(BaseTypeDeclarationSyntax stx)
        {
            List <BaseTypeDeclarationSyntax> declarations = new(){ stx };

            foreach (var baseTypeDeclarationSyntax in stx.ChildNodes().OfType <BaseTypeDeclarationSyntax>())
            {
                declarations.AddRange(DoParseFile(baseTypeDeclarationSyntax));
            }
            return(declarations);
        }
Exemple #2
0
        protected override SyntaxNode GetUpdatedTypeSyntax(Document document, BaseTypeDeclarationSyntax syntax)
        {
            var method = syntax.ChildNodes().OfType <MethodDeclarationSyntax>().First(_ => _.IsTestOneTimeSetUpMethod());

            var modifiedType = syntax.RemoveNodeAndAdjustOpenCloseBraces(method);

            var firstMethod = modifiedType.ChildNodes().OfType <MethodDeclarationSyntax>().First();

            return(modifiedType.InsertNodeBefore(firstMethod, method));
        }
        private static IReadOnlyCollection <string> DetermineImplementedTypes(BaseTypeDeclarationSyntax node)
        {
            var baseList = node.ChildNodes().OfType <BaseListSyntax>().FirstOrDefault();

            if (baseList == null)
            {
                return(Array.Empty <string>());
            }

            var childTypes = baseList.Types.Select(x => x.ToString()).FastToList();

            return(childTypes.AsReadOnly());
        }
Exemple #4
0
        protected override SyntaxNode GetUpdatedTypeSyntax(Document document, BaseTypeDeclarationSyntax syntax)
        {
            var method = syntax.ChildNodes().OfType <MethodDeclarationSyntax>().First(_ => _.IsTestOneTimeTearDownMethod());

            var modifiedType = syntax.RemoveNodeAndAdjustOpenCloseBraces(method);

            var firstMethod = modifiedType.ChildNodes().OfType <MethodDeclarationSyntax>().First();

            if (firstMethod.IsTestOneTimeSetUpMethod())
            {
                // we have to add the trivia to the method (as the original one belonged to the open brace token which we removed above)
                return(modifiedType.InsertNodeAfter(firstMethod, method.WithLeadingEndOfLine()));
            }

            return(modifiedType.InsertNodeBefore(firstMethod, method));
        }
        private static string DetermineName(BaseTypeDeclarationSyntax node)
        {
            var name = string.Empty;

            name += node.Identifier.Text;

            var typeParameters = node.ChildNodes().OfType <TypeParameterListSyntax>().FirstOrDefault();

            if (typeParameters == null)
            {
                return(name);
            }

            var parameterList = typeParameters.ToString();

            return(name + parameterList);
        }
Exemple #6
0
        protected override SyntaxNode GetUpdatedTypeSyntax(Document document, BaseTypeDeclarationSyntax syntax)
        {
            var method = syntax.ChildNodes().OfType<MethodDeclarationSyntax>().First(_ => _.IsTestSetUpMethod());

            var modifiedType = syntax.RemoveNodeAndAdjustOpenCloseBraces(method);

            var otherMethods = modifiedType.ChildNodes().OfType<MethodDeclarationSyntax>().ToList();

            var precedingNode = otherMethods.FirstOrDefault(_ => _.IsTestOneTimeTearDownMethod())
                             ?? otherMethods.FirstOrDefault(_ => _.IsTestOneTimeSetUpMethod());

            if (precedingNode is null)
            {
                // place before all other nodes as there is no one-time method
                return modifiedType.InsertNodeBefore(otherMethods.First(), method);
            }

            // we have to add the trivia to the method (as the original one belonged to the open brace token which we removed above)
            return modifiedType.InsertNodeAfter(precedingNode, method.WithLeadingEndOfLine());
        }