@@ -52,6 +52,23 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
52
52
53
53
foreach ( var usingSyntax in root . Usings )
54
54
{
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
+
55
72
var symbolInfo = semanticModel . GetSymbolInfo ( usingSyntax . Name ) ;
56
73
if ( symbolInfo . Symbol != null )
57
74
{
@@ -62,21 +79,13 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
62
79
}
63
80
else
64
81
{
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 ) ;
78
83
}
79
84
}
85
+ else
86
+ {
87
+ addUsing ( usingSyntax ) ;
88
+ }
80
89
}
81
90
82
91
if ( ! needsChanges )
@@ -86,6 +95,7 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
86
95
87
96
TransformationTracker transformationTracker = new TransformationTracker ( ) ;
88
97
RemoveTestClassAttributes ( root , semanticModel , transformationTracker ) ;
98
+ RemoveContractsRequiredAttributes ( root , semanticModel , transformationTracker ) ;
89
99
ChangeTestMethodAttributesToFact ( root , semanticModel , transformationTracker ) ;
90
100
ChangeAssertCalls ( root , semanticModel , transformationTracker ) ;
91
101
root = transformationTracker . TransformRoot ( root ) ;
@@ -115,7 +125,17 @@ public async Task<Solution> ProcessAsync(Document document, SyntaxNode syntaxNod
115
125
return document . WithSyntaxRoot ( root ) . Project . Solution ;
116
126
}
117
127
128
+ private void RemoveContractsRequiredAttributes ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
129
+ {
130
+ RemoveTestAttributes ( root , semanticModel , transformationTracker , "ContractsRequiredAttribute" ) ;
131
+ }
132
+
118
133
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 )
119
139
{
120
140
List < AttributeSyntax > nodesToRemove = new List < AttributeSyntax > ( ) ;
121
141
@@ -127,7 +147,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
127
147
if ( typeInfo . Type != null )
128
148
{
129
149
string attributeTypeDocID = typeInfo . Type . GetDocumentationCommentId ( ) ;
130
- if ( IsTestNamespaceType ( attributeTypeDocID , "TestClassAttribute" ) )
150
+ if ( IsTestNamespaceType ( attributeTypeDocID , attributeName ) )
131
151
{
132
152
return true ;
133
153
}
@@ -156,6 +176,7 @@ private void RemoveTestClassAttributes(CompilationUnitSyntax root, SemanticModel
156
176
return transformationRoot ;
157
177
} ) ;
158
178
}
179
+
159
180
private void ChangeTestMethodAttributesToFact ( CompilationUnitSyntax root , SemanticModel semanticModel , TransformationTracker transformationTracker )
160
181
{
161
182
List < AttributeSyntax > nodesToReplace = new List < AttributeSyntax > ( ) ;
0 commit comments