Open JohanLarsson opened 5 years ago
Maybe ASP002
[Test]
public void WhenRouteOnClass()
{
var code = @"
namespace AspBox
{
using Microsoft.AspNetCore.Mvc;
[Route(""api/values/{↓wrong}"")]
[ApiController]
public class OrdersController : Controller
{
[HttpGet]
public IActionResult GetValue(int id)
{
return this.Ok(id);
}
}
}";
var fixedCode = @"
namespace AspBox
{
using Microsoft.AspNetCore.Mvc;
[Route(""api/values/{id}"")]
[ApiController]
public class OrdersController : Controller
{
[HttpGet]
public IActionResult GetValue(int id)
{
return this.Ok(id);
}
}
}";
AnalyzerAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, code, fixedCode);
}
And ASP007
[Test]
public void WhenRouteOnClass()
{
var code = @"
namespace AspBox
{
using Microsoft.AspNetCore.Mvc;
[Route(""api/values/{↓id}"")]
[ApiController]
public class OrdersController : Controller
{
[HttpGet]
public IActionResult GetValue()
{
return this.Ok();
}
}
}";
AnalyzerAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code);
}
I'm not sure if this issue is relevant . Please, let me know if I should create a new one or comment on another one.
The warning below is emitted when building my project where route is defined on class.
CSC : warning AD0001: Analyzer 'AspNetCoreAnalyzers.AttributeAnalyzer' threw an exception of type 'System.IndexOutOfRangeException' with message 'Index was outside the bounds of the array.'.
Create new empty ASP Net Core Web Application Add the following class
using Microsoft.AspNetCore.Mvc;
namespace AnalyzerBugRepro
{
[ApiController]
[Route("api/")]
public class GrantStubController : ControllerBase
{
}
}
Build the project Observe the error in build output.
Ah, that looks like a separate/new issue.
Never hesitate to create issues, especially beautiful issues with repro code like you provided. Makes adding a test and then fixing fast and easy.
Thanks for reporting!