Skip to content

Commit aee729a

Browse files
committed
Improve existing test
1 parent a2e3677 commit aee729a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.Responses.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ public async Task GetOpenApiResponse_UsesDescriptionSetByUser()
315315
const string expectedBadRequestDescription = "Validation failed for the request";
316316

317317
// Act
318-
builder.MapGet("/api/todos",
319-
[ProducesResponseType(typeof(TimeSpan), StatusCodes.Status201Created, Description = expectedCreatedDescription)]
320-
[ProducesResponseType(StatusCodes.Status400BadRequest, Description = expectedBadRequestDescription)]
318+
builder.MapPost("/api/todos",
319+
[ProducesResponseType<Todo>(StatusCodes.Status200OK, Description = expectedCreatedDescription)]
320+
[ProducesResponseType(StatusCodes.Status400BadRequest)] // Omitted, meaning it should be NULL
321321
() =>
322-
{ });
322+
{ return TypedResults.Ok(new Todo(1, "Lorem", true, DateTime.UtcNow)); }); // This code doesn't return Bad Request, but that doesn't matter for this test.
323323

324324
// Assert
325325
await VerifyOpenApiDocument(builder, document =>
@@ -328,7 +328,7 @@ await VerifyOpenApiDocument(builder, document =>
328328
Assert.Collection(operation.Responses.OrderBy(r => r.Key),
329329
response =>
330330
{
331-
Assert.Equal("201", response.Key);
331+
Assert.Equal("200", response.Key);
332332
Assert.Equal(expectedCreatedDescription, response.Value.Description);
333333
},
334334
response =>
@@ -346,11 +346,11 @@ public async Task GetOpenApiResponse_UsesStatusCodeReasonPhraseWhenExplicitDescr
346346
var builder = CreateBuilder();
347347

348348
// Act
349-
builder.MapGet("/api/todos",
350-
[ProducesResponseType(typeof(TimeSpan), StatusCodes.Status201Created, Description = null)] // Explicitly set to NULL
349+
builder.MapPost("/api/todos",
350+
[ProducesResponseType<Todo>(StatusCodes.Status200OK, Description = null)] // Explicitly set to NULL
351351
[ProducesResponseType(StatusCodes.Status400BadRequest)] // Omitted, meaning it should be NULL
352352
() =>
353-
{ });
353+
{ return TypedResults.Ok(new Todo(1, "Lorem", true, DateTime.UtcNow)); }); // This code doesn't return Bad Request, but that doesn't matter for this test.
354354

355355
// Assert
356356
await VerifyOpenApiDocument(builder, document =>
@@ -359,8 +359,8 @@ await VerifyOpenApiDocument(builder, document =>
359359
Assert.Collection(operation.Responses.OrderBy(r => r.Key),
360360
response =>
361361
{
362-
Assert.Equal("201", response.Key);
363-
Assert.Equal("Created", response.Value.Description);
362+
Assert.Equal("200", response.Key);
363+
Assert.Equal("OK", response.Value.Description);
364364
},
365365
response =>
366366
{

0 commit comments

Comments
 (0)