|
12 | 12 | using Microsoft.OpenApi.Models; |
13 | 13 | using Microsoft.OpenApi.Readers; |
14 | 14 | using System.Text; |
| 15 | +using Microsoft.OpenApi.Reader; |
15 | 16 |
|
16 | 17 | public class OpenApiEndpointRouteBuilderExtensionsTests : OpenApiDocumentServiceTestBase |
17 | 18 | { |
@@ -67,7 +68,7 @@ public async Task MapOpenApi_ReturnsRenderedDocument() |
67 | 68 |
|
68 | 69 | // Assert |
69 | 70 | Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); |
70 | | - ValidateOpenApiDocument(responseBodyStream, document => |
| 71 | + await ValidateOpenApiDocumentAsync(responseBodyStream, document => |
71 | 72 | { |
72 | 73 | Assert.Equal("OpenApiEndpointRouteBuilderExtensionsTests | v1", document.Info.Title); |
73 | 74 | Assert.Equal("1.0.0", document.Info.Version); |
@@ -102,11 +103,11 @@ public async Task MapOpenApi_ReturnsDefaultDocumentIfNoNameProvided(string expec |
102 | 103 | // String check to validate that generated document starts with YAML syntax |
103 | 104 | Assert.Equal(isYaml, responseString.StartsWith("openapi: '3.1.1'", StringComparison.OrdinalIgnoreCase)); |
104 | 105 | responseBodyStream.Position = 0; |
105 | | - ValidateOpenApiDocument(responseBodyStream, document => |
| 106 | + await ValidateOpenApiDocumentAsync(responseBodyStream, document => |
106 | 107 | { |
107 | 108 | Assert.Equal("OpenApiEndpointRouteBuilderExtensionsTests | v1", document.Info.Title); |
108 | 109 | Assert.Equal("1.0.0", document.Info.Version); |
109 | | - }); |
| 110 | + }, isYaml ? "yaml" : "json"); |
110 | 111 | } |
111 | 112 |
|
112 | 113 | [Fact] |
@@ -163,16 +164,18 @@ public async Task MapOpenApi_ReturnsDocumentIfNameProvidedInQuery(string expecte |
163 | 164 | // String check to validate that generated document starts with YAML syntax |
164 | 165 | Assert.Equal(isYaml, responseString.StartsWith("openapi: '3.1.1'", StringComparison.OrdinalIgnoreCase)); |
165 | 166 | responseBodyStream.Position = 0; |
166 | | - ValidateOpenApiDocument(responseBodyStream, document => |
| 167 | + await ValidateOpenApiDocumentAsync(responseBodyStream, document => |
167 | 168 | { |
168 | 169 | Assert.Equal($"OpenApiEndpointRouteBuilderExtensionsTests | {documentName}", document.Info.Title); |
169 | 170 | Assert.Equal("1.0.0", document.Info.Version); |
170 | | - }); |
| 171 | + }, isYaml ? "yaml" : "json"); |
171 | 172 | } |
172 | 173 |
|
173 | | - private static async void ValidateOpenApiDocument(MemoryStream documentStream, Action<OpenApiDocument> action) |
| 174 | + private static async Task ValidateOpenApiDocumentAsync(MemoryStream documentStream, Action<OpenApiDocument> action, string format = "json") |
174 | 175 | { |
175 | | - var result = await OpenApiDocument.LoadAsync(documentStream, "json"); |
| 176 | + documentStream.Position = 0; |
| 177 | + OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader()); |
| 178 | + var result = await OpenApiDocument.LoadAsync(documentStream, format); |
176 | 179 | Assert.Empty(result.OpenApiDiagnostic.Errors); |
177 | 180 | action(result.OpenApiDocument); |
178 | 181 | } |
|
0 commit comments