DotNetAnalyzers / AspNetCoreAnalyzers

MIT License
62 stars 4 forks source link

ASP003 when [Route] on class and multiple actions. #58

Open JohanLarsson opened 5 years ago

JohanLarsson commented 5 years ago
        [Test]
        public void WhenHttpGetPutAndRouteOnClass()
        {
            var code = @"
namespace AspBox
{
    using Microsoft.AspNetCore.Mvc;

    [Route(""api/orders/{id:int}"")]
    [ApiController]
    public class OrdersController : Controller
    {
        [HttpGet]
        public IActionResult Get(↓byte id)
        {
            return this.Ok(id);
        }

        [HttpPut]
        public void Put(↓byte id, [FromBody] string value)
        {
        }
    }
}";

            var fixedCode = @"
namespace AspBox
{
    using Microsoft.AspNetCore.Mvc;

    [Route(""api/orders/{id:int}"")]
    [ApiController]
    public class OrdersController : Controller
    {
        [HttpGet]
        public IActionResult Get(int id)
        {
            return this.Ok(id);
        }

        [HttpPut]
        public void Put(int id, [FromBody] string value)
        {
        }
    }
}";
            AnalyzerAssert.FixAll(Analyzer, Fix, ExpectedDiagnostic, code, fixedCode);
        }