Skip to content

Commit

Permalink
Added test to prove we can POST an empty body. Closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Jul 27, 2024
1 parent 27aa935 commit ddee5a3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/ApiHost1/Api/TestingOnly/TestingWebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public async Task<ApiPostResult<string, StringMessageTestingOnlyResponse>> Gener
"alocation");
}

public async Task<ApiPostResult<string, StringMessageTestingOnlyResponse>> GeneralEmptyBodyPost(
PostWithEmptyBodyTestingOnlyRequest request, CancellationToken cancellationToken)
{
await Task.CompletedTask;
return () =>
new PostResult<StringMessageTestingOnlyResponse>(
new StringMessageTestingOnlyResponse { Message = "amessage" },
"alocation");
}

public async Task<ApiEmptyResult> GetInsecure(
GetInsecureTestingOnlyRequest request, CancellationToken cancellationToken)
{
Expand Down
11 changes: 10 additions & 1 deletion src/Infrastructure.Web.Api.IntegrationTests/GeneralApiSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public GeneralApiSpec(WebApiSetup<ApiHost1.Program> setup) : base(setup)
}

[Fact]
public async Task WhenGetError_ThenReturnsError()
public async Task WhenPostWithEnum_ThenReturns()
{
var result = await Api.PostAsync(new PostWithEnumTestingOnlyRequest
{
Expand All @@ -29,5 +29,14 @@ public async Task WhenGetError_ThenReturnsError()
result.StatusCode.Should().Be(HttpStatusCode.Created);
result.Content.Value.Message.Should().Be("amessageValue1");
}

[Fact]
public async Task WhenPostWithEmptyBody_ThenReturns()
{
var result = await Api.PostAsync(new PostWithEmptyBodyTestingOnlyRequest());

result.StatusCode.Should().Be(HttpStatusCode.Created);
result.Content.Value.Message.Should().Be("amessage");
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#if TESTINGONLY
using Infrastructure.Web.Api.Interfaces;

namespace Infrastructure.Web.Api.Operations.Shared.TestingOnly;

/// <summary>
/// Tests the use of an empty post body
/// </summary>
[Route("/testingonly/general/body/empty", OperationMethod.Post, isTestingOnly: true)]
public class PostWithEmptyBodyTestingOnlyRequest : IWebRequest<StringMessageTestingOnlyResponse>
{
}

#endif

0 comments on commit ddee5a3

Please sign in to comment.