Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirk Munro authored and Kirk Munro committed Oct 24, 2024
1 parent 33b2101 commit 829b983
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public Task<IActionResult> 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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 829b983

Please sign in to comment.