From 829b983588d989aa50f0648ccd1ae75f0de30620 Mon Sep 17 00:00:00 2001 From: Kirk Munro Date: Thu, 24 Oct 2024 09:44:21 -0300 Subject: [PATCH] fix unit tests --- .../Controllers/Parameters/FileUploadController.cs | 4 ++-- .../Parameters/HeaderParametersController.cs | 2 +- .../Parameters/SimpleQueryParametersController.cs | 2 +- .../Parameters/FormDataTests.cs | 8 +++++++- .../Parameters/QueryParametersTests.cs | 14 ++++++++------ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/FileUploadController.cs b/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/FileUploadController.cs index 49ddb6d8a0..7ac69dd5dd 100644 --- a/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/FileUploadController.cs +++ b/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/FileUploadController.cs @@ -32,9 +32,9 @@ public Task UploadAttachment( public class CaseAttachmentModel { - public string Description { get; set; } + public string? Description { get; set; } - public IFormFile Contents { get; set; } + public IFormFile? Contents { get; set; } } [HttpPost("UploadAttachment2")] diff --git a/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/HeaderParametersController.cs b/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/HeaderParametersController.cs index 932542324e..0cedb1f514 100644 --- a/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/HeaderParametersController.cs +++ b/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/HeaderParametersController.cs @@ -7,7 +7,7 @@ namespace NSwag.Generation.AspNetCore.Tests.Web.Controllers.Parameters public class HeaderParametersController : Controller { [HttpGet] - public ActionResult MyAction([FromHeader] string required, [FromHeader] string optional = null) + public ActionResult MyAction([FromHeader] string required, [FromHeader] string? optional = null) { return Ok(); } diff --git a/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/SimpleQueryParametersController.cs b/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/SimpleQueryParametersController.cs index 97c93f95ba..25093331ca 100644 --- a/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/SimpleQueryParametersController.cs +++ b/src/NSwag.Generation.AspNetCore.Tests.Web/Controllers/Parameters/SimpleQueryParametersController.cs @@ -8,7 +8,7 @@ namespace NSwag.Generation.AspNetCore.Tests.Web.Controllers.Parameters public class SimpleQueryParametersController : Controller { [HttpGet] - public ActionResult GetList(int? required, int optional = 10, [BindRequired, FromQuery] string requiredString = null) + public ActionResult GetList(int requiredBecauseNonNullable, int? optionalBecauseNullable, int? optionalBecauseNullableWithDefaultValue = 10, [BindRequired, FromQuery] string? requiredBecauseBindRequired = null) { return Ok(); } diff --git a/src/NSwag.Generation.AspNetCore.Tests/Parameters/FormDataTests.cs b/src/NSwag.Generation.AspNetCore.Tests/Parameters/FormDataTests.cs index 2166874f70..2a6ed9bf17 100644 --- a/src/NSwag.Generation.AspNetCore.Tests/Parameters/FormDataTests.cs +++ b/src/NSwag.Generation.AspNetCore.Tests/Parameters/FormDataTests.cs @@ -43,16 +43,22 @@ public async Task WhenOperationHasFormDataFile_ThenItIsInRequestBody() ""content"": { ""multipart/form-data"": { ""schema"": { + ""required"": [ + ""files"", + ""test"" + ], ""properties"": { ""files"": { ""type"": ""array"", + ""nullable"": false, ""items"": { ""type"": ""string"", ""format"": ""binary"" } }, ""test"": { - ""type"": ""string"" + ""type"": ""string"", + ""nullable"": false } } } diff --git a/src/NSwag.Generation.AspNetCore.Tests/Parameters/QueryParametersTests.cs b/src/NSwag.Generation.AspNetCore.Tests/Parameters/QueryParametersTests.cs index cf83460910..ec61d0cbd4 100644 --- a/src/NSwag.Generation.AspNetCore.Tests/Parameters/QueryParametersTests.cs +++ b/src/NSwag.Generation.AspNetCore.Tests/Parameters/QueryParametersTests.cs @@ -54,10 +54,11 @@ public async Task When_simple_query_parameters_are_nullable_and_set_to_null_they // Assert var operation = document.Operations.First().Operation; - Assert.Equal(3, operation.ActualParameters.Count); + Assert.Equal(4, operation.ActualParameters.Count); Assert.True(operation.ActualParameters.Skip(0).First().IsRequired); - Assert.False(operation.ActualParameters.Skip(1).First().IsRequired); - Assert.True(operation.ActualParameters.Skip(2).First().IsRequired); + Assert.True(operation.ActualParameters.Skip(1).First().IsRequired); + Assert.False(operation.ActualParameters.Skip(2).First().IsRequired); + Assert.True(operation.ActualParameters.Skip(3).First().IsRequired); } [Fact] @@ -76,10 +77,11 @@ public async Task When_simple_query_parameter_has_BindRequiredAttribute_then_it_ // Assert var operation = document.Operations.First().Operation; - Assert.Equal(3, operation.ActualParameters.Count); - Assert.False(operation.ActualParameters.Skip(0).First().IsRequired); + Assert.Equal(4, operation.ActualParameters.Count); + Assert.True(operation.ActualParameters.Skip(0).First().IsRequired); Assert.False(operation.ActualParameters.Skip(1).First().IsRequired); - Assert.True(operation.ActualParameters.Skip(2).First().IsRequired); + Assert.False(operation.ActualParameters.Skip(2).First().IsRequired); + Assert.True(operation.ActualParameters.Skip(3).First().IsRequired); } [Fact]