From ddee5a3b2fe56d94f887d10bd0e7a72b8011fe95 Mon Sep 17 00:00:00 2001 From: Jezz Santos Date: Sat, 27 Jul 2024 17:44:27 +1200 Subject: [PATCH] Added test to prove we can POST an empty body. Closes #37 --- src/ApiHost1/Api/TestingOnly/TestingWebApi.cs | 10 ++++++++++ .../GeneralApiSpec.cs | 11 ++++++++++- .../PostWithEmptyBodyTestingOnlyRequest.cs | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/Infrastructure.Web.Api.Operations.Shared/TestingOnly/PostWithEmptyBodyTestingOnlyRequest.cs diff --git a/src/ApiHost1/Api/TestingOnly/TestingWebApi.cs b/src/ApiHost1/Api/TestingOnly/TestingWebApi.cs index 7e39511f..9012b86f 100644 --- a/src/ApiHost1/Api/TestingOnly/TestingWebApi.cs +++ b/src/ApiHost1/Api/TestingOnly/TestingWebApi.cs @@ -129,6 +129,16 @@ public async Task> Gener "alocation"); } + public async Task> GeneralEmptyBodyPost( + PostWithEmptyBodyTestingOnlyRequest request, CancellationToken cancellationToken) + { + await Task.CompletedTask; + return () => + new PostResult( + new StringMessageTestingOnlyResponse { Message = "amessage" }, + "alocation"); + } + public async Task GetInsecure( GetInsecureTestingOnlyRequest request, CancellationToken cancellationToken) { diff --git a/src/Infrastructure.Web.Api.IntegrationTests/GeneralApiSpec.cs b/src/Infrastructure.Web.Api.IntegrationTests/GeneralApiSpec.cs index 87c6ed2b..1f0140a1 100644 --- a/src/Infrastructure.Web.Api.IntegrationTests/GeneralApiSpec.cs +++ b/src/Infrastructure.Web.Api.IntegrationTests/GeneralApiSpec.cs @@ -18,7 +18,7 @@ public GeneralApiSpec(WebApiSetup setup) : base(setup) } [Fact] - public async Task WhenGetError_ThenReturnsError() + public async Task WhenPostWithEnum_ThenReturns() { var result = await Api.PostAsync(new PostWithEnumTestingOnlyRequest { @@ -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 \ No newline at end of file diff --git a/src/Infrastructure.Web.Api.Operations.Shared/TestingOnly/PostWithEmptyBodyTestingOnlyRequest.cs b/src/Infrastructure.Web.Api.Operations.Shared/TestingOnly/PostWithEmptyBodyTestingOnlyRequest.cs new file mode 100644 index 00000000..0edfb774 --- /dev/null +++ b/src/Infrastructure.Web.Api.Operations.Shared/TestingOnly/PostWithEmptyBodyTestingOnlyRequest.cs @@ -0,0 +1,14 @@ +#if TESTINGONLY +using Infrastructure.Web.Api.Interfaces; + +namespace Infrastructure.Web.Api.Operations.Shared.TestingOnly; + +/// +/// Tests the use of an empty post body +/// +[Route("/testingonly/general/body/empty", OperationMethod.Post, isTestingOnly: true)] +public class PostWithEmptyBodyTestingOnlyRequest : IWebRequest +{ +} + +#endif \ No newline at end of file