Skip to content

Commit 486e89b

Browse files
committed
ASP002 don't warn when wrong name.
1 parent 642c906 commit 486e89b

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

AspNetCoreAnalyzers.Tests/ASP002MissingParameterTests/ValidCode.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,28 @@ public async Task<IActionResult> GetOrder([FromHeader]int id)
172172
}";
173173
AnalyzerAssert.Valid(Analyzer, order, db, code);
174174
}
175+
176+
[Test]
177+
public void WhenWrongName()
178+
{
179+
var code = @"
180+
namespace ValidCode
181+
{
182+
using System.Threading.Tasks;
183+
using Microsoft.AspNetCore.Mvc;
184+
using Microsoft.EntityFrameworkCore;
185+
186+
[ApiController]
187+
public class OrdersController : Controller
188+
{
189+
[HttpGet(""api/{value}"")]
190+
public IActionResult GetValue(string wrongName)
191+
{
192+
return this.Ok(wrongName);
193+
}
194+
}
195+
}";
196+
AnalyzerAssert.Valid(Analyzer, ASP002MissingParameter.Descriptor, code);
197+
}
175198
}
176199
}

AspNetCoreAnalyzers/Analyzers/AttributeAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ context.ContainingSymbol is IMethodSymbol method &&
5858
methodDeclaration.ParameterList.GetLocation()));
5959
}
6060

61-
if (pairs.TryFirst(x => x.Method == null, out _))
61+
if (pairs.TryFirst(x => x.Method == null, out _) &&
62+
!pairs.TryFirst(x => x.Template == null, out _))
6263
{
6364
context.ReportDiagnostic(
6465
Diagnostic.Create(

0 commit comments

Comments
 (0)