1
- namespace AspNetCoreAnalyzers . Tests . ASP001ParameterNameTests
2
- {
3
- using Gu . Roslyn . Asserts ;
4
- using Microsoft . CodeAnalysis . CodeFixes ;
5
- using Microsoft . CodeAnalysis . Diagnostics ;
6
- using NUnit . Framework ;
1
+ namespace AspNetCoreAnalyzers . Tests . ASP001ParameterNameTests ;
2
+
3
+ using Gu . Roslyn . Asserts ;
4
+ using Microsoft . CodeAnalysis . CodeFixes ;
5
+ using Microsoft . CodeAnalysis . Diagnostics ;
6
+ using NUnit . Framework ;
7
7
8
- public static class CodeFix
8
+ public static class CodeFix
9
+ {
10
+ private static readonly DiagnosticAnalyzer Analyzer = new AttributeAnalyzer ( ) ;
11
+ private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic . Create ( Descriptors . ASP001ParameterSymbolName ) ;
12
+ private static readonly CodeFixProvider Fix = new RenameParameterFix ( ) ;
13
+
14
+ [ TestCase ( "\" {value}\" " ) ]
15
+ [ TestCase ( "@\" {value}\" " ) ]
16
+ [ TestCase ( "\" {value?}\" " ) ]
17
+ [ TestCase ( "\" {*value}\" " ) ]
18
+ [ TestCase ( "\" {**value}\" " ) ]
19
+ [ TestCase ( "\" {value=abc}\" " ) ]
20
+ [ TestCase ( "@\" {value?}\" " ) ]
21
+ [ TestCase ( "\" api/orders/{value}\" " ) ]
22
+ [ TestCase ( "\" api/orders/{value?}\" " ) ]
23
+ [ TestCase ( "\" api/orders/{value:alpha}\" " ) ]
24
+ [ TestCase ( "\" api/orders/{value:regex(a-(0|1))}\" " ) ]
25
+ [ TestCase ( "\" api/orders/{value:regex(^\\ \\ d{{3}}-\\ \\ d{{2}}-\\ \\ d{4}$)}\" " ) ]
26
+ public static void WhenHttpGet ( string template )
9
27
{
10
- private static readonly DiagnosticAnalyzer Analyzer = new AttributeAnalyzer ( ) ;
11
- private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic . Create ( Descriptors . ASP001ParameterSymbolName ) ;
12
- private static readonly CodeFixProvider Fix = new RenameParameterFix ( ) ;
13
-
14
- [ TestCase ( "\" {value}\" " ) ]
15
- [ TestCase ( "@\" {value}\" " ) ]
16
- [ TestCase ( "\" {value?}\" " ) ]
17
- [ TestCase ( "\" {*value}\" " ) ]
18
- [ TestCase ( "\" {**value}\" " ) ]
19
- [ TestCase ( "\" {value=abc}\" " ) ]
20
- [ TestCase ( "@\" {value?}\" " ) ]
21
- [ TestCase ( "\" api/orders/{value}\" " ) ]
22
- [ TestCase ( "\" api/orders/{value?}\" " ) ]
23
- [ TestCase ( "\" api/orders/{value:alpha}\" " ) ]
24
- [ TestCase ( "\" api/orders/{value:regex(a-(0|1))}\" " ) ]
25
- [ TestCase ( "\" api/orders/{value:regex(^\\ \\ d{{3}}-\\ \\ d{{2}}-\\ \\ d{4}$)}\" " ) ]
26
- public static void WhenHttpGet ( string template )
27
- {
28
- var before = @"
28
+ var before = @"
29
29
namespace AspBox
30
30
{
31
31
using Microsoft.AspNetCore.Mvc;
@@ -41,7 +41,7 @@ public IActionResult GetId(string ↓wrong)
41
41
}
42
42
}" . AssertReplace ( "\" api/orders/{value}\" " , template ) ;
43
43
44
- var after = @"
44
+ var after = @"
45
45
namespace AspBox
46
46
{
47
47
using Microsoft.AspNetCore.Mvc;
@@ -56,13 +56,13 @@ public IActionResult GetId(string value)
56
56
}
57
57
}
58
58
}" . AssertReplace ( "\" api/orders/{value}\" " , template ) ;
59
- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
60
- }
59
+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
60
+ }
61
61
62
- [ Test ]
63
- public static void WhenRouteAndHttpGetOnMethod ( )
64
- {
65
- var before = @"
62
+ [ Test ]
63
+ public static void WhenRouteAndHttpGetOnMethod ( )
64
+ {
65
+ var before = @"
66
66
namespace AspBox
67
67
{
68
68
using Microsoft.AspNetCore.Mvc;
@@ -79,7 +79,7 @@ public IActionResult GetId(string ↓wrong)
79
79
}
80
80
}" ;
81
81
82
- var after = @"
82
+ var after = @"
83
83
namespace AspBox
84
84
{
85
85
using Microsoft.AspNetCore.Mvc;
@@ -95,13 +95,13 @@ public IActionResult GetId(string value)
95
95
}
96
96
}
97
97
}" ;
98
- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
99
- }
98
+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
99
+ }
100
100
101
- [ Test ]
102
- public static void ImplicitSingleParameter ( )
103
- {
104
- var order = @"
101
+ [ Test ]
102
+ public static void ImplicitSingleParameter ( )
103
+ {
104
+ var order = @"
105
105
namespace AspBox
106
106
{
107
107
public class Order
@@ -110,7 +110,7 @@ public class Order
110
110
}
111
111
}" ;
112
112
113
- var db = @"
113
+ var db = @"
114
114
namespace AspBox
115
115
{
116
116
using Microsoft.EntityFrameworkCore;
@@ -120,7 +120,7 @@ public class Db : DbContext
120
120
public DbSet<Order> Orders => this.Set<Order>();
121
121
}
122
122
}" ;
123
- var before = @"
123
+ var before = @"
124
124
namespace AspBox
125
125
{
126
126
using System.Threading.Tasks;
@@ -151,7 +151,7 @@ public async Task<IActionResult> GetOrder(int ↓wrong)
151
151
}
152
152
}" ;
153
153
154
- var after = @"
154
+ var after = @"
155
155
namespace AspBox
156
156
{
157
157
using System.Threading.Tasks;
@@ -181,13 +181,13 @@ public async Task<IActionResult> GetOrder(int id)
181
181
}
182
182
}
183
183
}" ;
184
- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , new [ ] { order , db , before } , after ) ;
185
- }
184
+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , new [ ] { order , db , before } , after ) ;
185
+ }
186
186
187
- [ Test ]
188
- public static void FirstParameter ( )
189
- {
190
- var before = @"
187
+ [ Test ]
188
+ public static void FirstParameter ( )
189
+ {
190
+ var before = @"
191
191
namespace AspBox
192
192
{
193
193
using Microsoft.AspNetCore.Mvc;
@@ -203,7 +203,7 @@ public IActionResult GetOrder(int ↓wrong, int itemId)
203
203
}
204
204
}" ;
205
205
206
- var after = @"
206
+ var after = @"
207
207
namespace AspBox
208
208
{
209
209
using Microsoft.AspNetCore.Mvc;
@@ -218,13 +218,13 @@ public IActionResult GetOrder(int orderId, int itemId)
218
218
}
219
219
}
220
220
}" ;
221
- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
222
- }
221
+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
222
+ }
223
223
224
- [ Test ]
225
- public static void LastParameter ( )
226
- {
227
- var before = @"
224
+ [ Test ]
225
+ public static void LastParameter ( )
226
+ {
227
+ var before = @"
228
228
namespace AspBox
229
229
{
230
230
using Microsoft.AspNetCore.Mvc;
@@ -240,7 +240,7 @@ public IActionResult GetOrder(int orderId, int ↓wrong)
240
240
}
241
241
}" ;
242
242
243
- var after = @"
243
+ var after = @"
244
244
namespace AspBox
245
245
{
246
246
using Microsoft.AspNetCore.Mvc;
@@ -255,13 +255,13 @@ public IActionResult GetOrder(int orderId, int itemId)
255
255
}
256
256
}
257
257
}" ;
258
- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
259
- }
258
+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
259
+ }
260
260
261
- [ Test ]
262
- public static void ExplicitFromRouteAttributeSingleParameter ( )
263
- {
264
- var before = @"
261
+ [ Test ]
262
+ public static void ExplicitFromRouteAttributeSingleParameter ( )
263
+ {
264
+ var before = @"
265
265
namespace AspBox
266
266
{
267
267
using Microsoft.AspNetCore.Mvc;
@@ -277,7 +277,7 @@ public IActionResult GetId(string ↓wrong)
277
277
}
278
278
}" ;
279
279
280
- var after = @"
280
+ var after = @"
281
281
namespace AspBox
282
282
{
283
283
using Microsoft.AspNetCore.Mvc;
@@ -292,7 +292,6 @@ public IActionResult GetId(string value)
292
292
}
293
293
}
294
294
}" ;
295
- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
296
- }
295
+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
297
296
}
298
297
}
0 commit comments