Skip to content

Commit

Permalink
add UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Feb 23, 2024
1 parent ed93413 commit d28c5ae
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions rules/S6934/S6934.AspNetCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Routing;

public class NoActionHasHttpAttributeWithRouteController : Controller
{
public IActionResult Index() => View(); // Compliant

[HttpGet]
public IActionResult Index2() => View(); // Compliant, default behavior if not route template is defined

public IActionResult Error() => View(); // Compliant
}

public class ctionHasHttpAttributeWithRouteController : Controller
{
[HttpGet("GetObject")] // Noncompliant
public IActionResult Get() => View();

[HttpPost("CreateObject")] // Noncompliant
public IActionResult Post() => View();

[HttpPut("UpdateObject")] // Noncompliant
public IActionResult Put() => View();

[HttpDelete("DeleteObject")] // Noncompliant
public IActionResult Delete() => View();

[HttpPatch("PatchObject")] // Noncompliant
public IActionResult Patch() => View();

[HttpHead("Head")] // Noncompliant
public IActionResult HttpHead() => View();

[HttpOptions("Options")] // Noncompliant
public IActionResult HttpOptions() => View();
}

public class WithUserDefinedAttribute : Controller
{
[MyHttpMethod("Test")] // Compliant, behavior is user defined
public IActionResult Index() => View();

private sealed class MyHttpMethodAttribute(string template) : HttpMethodAttribute([template]) { }
}

0 comments on commit d28c5ae

Please sign in to comment.