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 ;
77
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 )
927 {
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 = @"
2929namespace AspBox
3030{
3131 using Microsoft.AspNetCore.Mvc;
@@ -41,7 +41,7 @@ public IActionResult GetId(string ↓wrong)
4141 }
4242}" . AssertReplace ( "\" api/orders/{value}\" " , template ) ;
4343
44- var after = @"
44+ var after = @"
4545namespace AspBox
4646{
4747 using Microsoft.AspNetCore.Mvc;
@@ -56,13 +56,13 @@ public IActionResult GetId(string value)
5656 }
5757 }
5858}" . AssertReplace ( "\" api/orders/{value}\" " , template ) ;
59- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
60- }
59+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
60+ }
6161
62- [ Test ]
63- public static void WhenRouteAndHttpGetOnMethod ( )
64- {
65- var before = @"
62+ [ Test ]
63+ public static void WhenRouteAndHttpGetOnMethod ( )
64+ {
65+ var before = @"
6666namespace AspBox
6767{
6868 using Microsoft.AspNetCore.Mvc;
@@ -79,7 +79,7 @@ public IActionResult GetId(string ↓wrong)
7979 }
8080}" ;
8181
82- var after = @"
82+ var after = @"
8383namespace AspBox
8484{
8585 using Microsoft.AspNetCore.Mvc;
@@ -95,13 +95,13 @@ public IActionResult GetId(string value)
9595 }
9696 }
9797}" ;
98- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
99- }
98+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
99+ }
100100
101- [ Test ]
102- public static void ImplicitSingleParameter ( )
103- {
104- var order = @"
101+ [ Test ]
102+ public static void ImplicitSingleParameter ( )
103+ {
104+ var order = @"
105105namespace AspBox
106106{
107107 public class Order
@@ -110,7 +110,7 @@ public class Order
110110 }
111111}" ;
112112
113- var db = @"
113+ var db = @"
114114namespace AspBox
115115{
116116 using Microsoft.EntityFrameworkCore;
@@ -120,7 +120,7 @@ public class Db : DbContext
120120 public DbSet<Order> Orders => this.Set<Order>();
121121 }
122122}" ;
123- var before = @"
123+ var before = @"
124124namespace AspBox
125125{
126126 using System.Threading.Tasks;
@@ -151,7 +151,7 @@ public async Task<IActionResult> GetOrder(int ↓wrong)
151151 }
152152}" ;
153153
154- var after = @"
154+ var after = @"
155155namespace AspBox
156156{
157157 using System.Threading.Tasks;
@@ -181,13 +181,13 @@ public async Task<IActionResult> GetOrder(int id)
181181 }
182182 }
183183}" ;
184- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , new [ ] { order , db , before } , after ) ;
185- }
184+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , new [ ] { order , db , before } , after ) ;
185+ }
186186
187- [ Test ]
188- public static void FirstParameter ( )
189- {
190- var before = @"
187+ [ Test ]
188+ public static void FirstParameter ( )
189+ {
190+ var before = @"
191191namespace AspBox
192192{
193193 using Microsoft.AspNetCore.Mvc;
@@ -203,7 +203,7 @@ public IActionResult GetOrder(int ↓wrong, int itemId)
203203 }
204204}" ;
205205
206- var after = @"
206+ var after = @"
207207namespace AspBox
208208{
209209 using Microsoft.AspNetCore.Mvc;
@@ -218,13 +218,13 @@ public IActionResult GetOrder(int orderId, int itemId)
218218 }
219219 }
220220}" ;
221- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
222- }
221+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
222+ }
223223
224- [ Test ]
225- public static void LastParameter ( )
226- {
227- var before = @"
224+ [ Test ]
225+ public static void LastParameter ( )
226+ {
227+ var before = @"
228228namespace AspBox
229229{
230230 using Microsoft.AspNetCore.Mvc;
@@ -240,7 +240,7 @@ public IActionResult GetOrder(int orderId, int ↓wrong)
240240 }
241241}" ;
242242
243- var after = @"
243+ var after = @"
244244namespace AspBox
245245{
246246 using Microsoft.AspNetCore.Mvc;
@@ -255,13 +255,13 @@ public IActionResult GetOrder(int orderId, int itemId)
255255 }
256256 }
257257}" ;
258- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
259- }
258+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
259+ }
260260
261- [ Test ]
262- public static void ExplicitFromRouteAttributeSingleParameter ( )
263- {
264- var before = @"
261+ [ Test ]
262+ public static void ExplicitFromRouteAttributeSingleParameter ( )
263+ {
264+ var before = @"
265265namespace AspBox
266266{
267267 using Microsoft.AspNetCore.Mvc;
@@ -277,7 +277,7 @@ public IActionResult GetId(string ↓wrong)
277277 }
278278}" ;
279279
280- var after = @"
280+ var after = @"
281281namespace AspBox
282282{
283283 using Microsoft.AspNetCore.Mvc;
@@ -292,7 +292,6 @@ public IActionResult GetId(string value)
292292 }
293293 }
294294}" ;
295- RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
296- }
295+ RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
297296 }
298297}
0 commit comments