Skip to content

Commit

Permalink
Add tests for supported razor page HTTP methods
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddotcs committed Jun 8, 2024
1 parent 9957e27 commit e724d70
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/Test/SafeRouting.Tests.Unit/PageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,81 @@ public void OnGet()
""", path: TestHelper.MakePath("Project", "Pages", "Products", "Edit.cshtml.cs"));
}

[Fact]
public Task HttpMethodsThatAreIncorrectlyCapitalisedAreExcluded()
{
return TestHelper.Verify("""
using Microsoft.AspNetCore.Mvc.RazorPages;
public sealed class EditModel : PageModel
{
public void Ondelete()
{
}
public void OnGET()
{
}
public void OnhEAD()
{
}
public void OnOpTiOnS()
{
}
}
""", path: TestHelper.MakePath("Project", "Pages", "Products", "Edit.cshtml.cs"));
}

[Fact]
public Task HttpMethodsThatAreSupportedAreIncluded()
{
return TestHelper.Verify("""
using Microsoft.AspNetCore.Mvc.RazorPages;
public sealed class EditModel : PageModel
{
public void OnDelete()
{
}
public void OnGet()
{
}
public void OnHead()
{
}
public void OnOptions()
{
}
public void OnPatch()
{
}
public void OnPost()
{
}
public void OnPut()
{
}
}
""", path: TestHelper.MakePath("Project", "Pages", "Products", "Edit.cshtml.cs"));
}

[Fact]
public Task HttpMethodsThatAreNotSupportedAreExcluded()
{
return TestHelper.Verify("""
using Microsoft.AspNetCore.Mvc.RazorPages;
public sealed class EditModel : PageModel
{
public void OnConnect()
{
}
public void OnTrace()
{
}
}
""", path: TestHelper.MakePath("Project", "Pages", "Products", "Edit.cshtml.cs"));
}

[Fact]
public Task InheritedMembersAreIncluded()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//HintName: globalusings.g.cs
// <auto-generated/>

global using static SafeRouting.Extensions.RouteValueExtensions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//HintName: globalusings.g.cs
// <auto-generated/>

global using static SafeRouting.Extensions.RouteValueExtensions;
Loading

0 comments on commit e724d70

Please sign in to comment.