Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit 35718a0

Browse files
committed
Added tests for error code 405
1 parent 3adad5d commit 35718a0

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

samples/PowerUtils.AspNetCore.ErrorHandler.Samples/Controllers/Errors4xxController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace PowerUtils.AspNetCore.ErrorHandler.Samples.Controllers;
88
[Route("errors-4xx")]
99
public class Errors4xxController : ControllerBase
1010
{
11+
[HttpGet]
12+
public IActionResult Get()
13+
=> Ok("Success...");
14+
1115
[HttpGet("400")]
1216
public IActionResult Error400()
1317
=> BadRequest();

src/PowerUtils.AspNetCore.ErrorHandler/ProblemDetailsFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private static string _formatPropertyToCamelCase(string propertyName)
136136
private static string _formatPropertyToSnakeCase(string propertyName)
137137
{
138138
var propertyParts = propertyName.Split('.');
139-
139+
140140
for(var count = 0; count < propertyParts.Length; count++)
141141
{
142142
propertyParts[count] = propertyParts[count].ToSnakeCase();

tests/PowerUtils.AspNetCore.ErrorHandler.Tests/ControllersTests/Errors4xxTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,24 @@ public async Task Error_422()
118118

119119
content.ValidateContent(HttpStatusCode.UnprocessableEntity);
120120
}
121+
122+
[Fact(DisplayName = "Using the verb POST to call an endpoint with verb GET - Should return a problem details response with error code 405")]
123+
public async Task GetEndpoint_UsePOSTVerbs_405()
124+
{
125+
// Arrange
126+
var requestUri = "/errors-4xx";
127+
128+
129+
// Act
130+
(var response, var content) = await _testsFixture.Client.SendPostAsync(requestUri);
131+
132+
133+
// Assert
134+
response.ValidateResponse(HttpStatusCode.MethodNotAllowed);
135+
136+
content.ValidateContent(
137+
HttpStatusCode.MethodNotAllowed,
138+
"POST: " + requestUri
139+
);
140+
}
121141
}

0 commit comments

Comments
 (0)