@@ -52,6 +52,23 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
5252
5353 foreach ( var usingSyntax in root . Usings )
5454 {
55+ Action < UsingDirectiveSyntax > addUsing = ( UsingDirectiveSyntax newUsingSyntax ) =>
56+ {
57+ UsingDirectiveSyntax usingDirectiveToUse = newUsingSyntax ;
58+ if ( usingDirectiveToUse . HasLeadingTrivia )
59+ {
60+ var newLeadingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetLeadingTrivia ( ) ) ;
61+ usingDirectiveToUse = usingDirectiveToUse . WithLeadingTrivia ( newLeadingTrivia ) ;
62+ }
63+ if ( usingDirectiveToUse . HasTrailingTrivia )
64+ {
65+ var newTrailingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetTrailingTrivia ( ) ) ;
66+ usingDirectiveToUse = usingDirectiveToUse . WithTrailingTrivia ( newTrailingTrivia ) ;
67+ }
68+
69+ newUsings . Add ( usingDirectiveToUse ) ;
70+ } ;
71+
5572 var symbolInfo = semanticModel . GetSymbolInfo ( usingSyntax . Name ) ;
5673 if ( symbolInfo . Symbol != null )
5774 {
@@ -62,21 +79,13 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
6279 }
6380 else
6481 {
65- UsingDirectiveSyntax usingDirectiveToUse = usingSyntax ;
66- if ( usingDirectiveToUse . HasLeadingTrivia )
67- {
68- var newLeadingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetLeadingTrivia ( ) ) ;
69- usingDirectiveToUse = usingDirectiveToUse . WithLeadingTrivia ( newLeadingTrivia ) ;
70- }
71- if ( usingDirectiveToUse . HasTrailingTrivia )
72- {
73- var newTrailingTrivia = RemoveCompilerDirectives ( usingDirectiveToUse . GetTrailingTrivia ( ) ) ;
74- usingDirectiveToUse = usingDirectiveToUse . WithTrailingTrivia ( newTrailingTrivia ) ;
75- }
76-
77- newUsings . Add ( usingDirectiveToUse ) ;
82+ addUsing ( usingSyntax ) ;
7883 }
7984 }
85+ else
86+ {
87+ addUsing ( usingSyntax ) ;
88+ }
8089 }
8190
8291 if ( ! needsChanges )
@@ -86,6 +95,7 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
8695
8796 TransformationTracker transformationTracker = new TransformationTracker ( ) ;
8897 RemoveTestClassAttributes ( root , semanticModel , transformationTracker ) ;
98+ RemoveContractsRequiredAttributes ( root , semanticModel , transformationTracker ) ;
8999 ChangeTestMethodAttributesToFact ( root , semanticModel , transformationTracker ) ;
90100 ChangeAssertCalls ( root , semanticModel , transformationTracker ) ;
91101 root = transformationTracker . TransformRoot ( root ) ;
@@ -115,7 +125,17 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
115125 return document . WithSyntaxRoot ( root ) . Project . Solution ;
116126 }
117127
128+ private void RemoveContractsRequiredAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
129+ {
130+ RemoveTestAttributes ( root , semanticModel , transformationTracker , "ContractsRequiredAttribute" ) ;
131+ }
132+
118133 private void RemoveTestClassAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
134+ {
135+ RemoveTestAttributes ( root , semanticModel , transformationTracker , "TestClassAttribute" ) ;
136+ }
137+
138+ private void RemoveTestAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker , string attributeName )
119139 {
120140 List < AttributeSyntax > nodesToRemove = new List < AttributeSyntax > ( ) ;
121141
@@ -127,7 +147,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
127147 if ( typeInfo . Type != null )
128148 {
129149 string attributeTypeDocID = typeInfo . Type . GetDocumentationCommentId ( ) ;
130- if ( IsTestNamespaceType ( attributeTypeDocID , "TestClassAttribute" ) )
150+ if ( IsTestNamespaceType ( attributeTypeDocID , attributeName ) )
131151 {
132152 return true ;
133153 }
@@ -156,6 +176,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
156176 return transformationRoot ;
157177 } ) ;
158178 }
179+
159180 private void ChangeTestMethodAttributesToFact ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
160181 {
161182 List < AttributeSyntax > nodesToReplace = new List < AttributeSyntax > ( ) ;
0 commit comments