Exemple #1
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));
        }
Exemple #2
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));
        }
Exemple #3
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());
        }