|
11 | 11 | using Microsoft.Extensions.Logging; |
12 | 12 | using System.Reflection; |
13 | 13 | using Xunit.Abstractions; |
| 14 | +using Microsoft.AspNetCore.Mvc.ApplicationModels; |
| 15 | +using Microsoft.Extensions.DependencyInjection; |
| 16 | +using Microsoft.AspNetCore.Mvc.ApiExplorer; |
| 17 | +using Microsoft.AspNetCore.Http.HttpResults; |
| 18 | +using Microsoft.AspNetCore.Http; |
14 | 19 |
|
15 | 20 | namespace Microsoft.AspNetCore.Mvc.FunctionalTests; |
16 | 21 |
|
@@ -1565,6 +1570,26 @@ public async Task ApiExplorer_LogsInvokedDescriptionProvidersOnStartup() |
1565 | 1570 | Assert.Contains(TestSink.Writes, w => w.Message.Equals("Executing API description provider 'JsonPatchOperationsArrayProvider' from assembly Microsoft.AspNetCore.Mvc.NewtonsoftJson v42.42.42.42.", StringComparison.Ordinal)); |
1566 | 1571 | } |
1567 | 1572 |
|
| 1573 | + [Fact] |
| 1574 | + public void ApiExplorer_BuildsMetadataForActionWithTypedResult() |
| 1575 | + { |
| 1576 | + var apiDescCollectionProvider = Factory.Server.Services.GetService<IApiDescriptionGroupCollectionProvider>(); |
| 1577 | + var testGroupName = nameof(ApiExplorerWithTypedResultController).Replace("Controller", string.Empty); |
| 1578 | + var group = apiDescCollectionProvider.ApiDescriptionGroups.Items.Where(i => i.GroupName == testGroupName).SingleOrDefault(); |
| 1579 | + Assert.NotNull(group); |
| 1580 | + var apiDescription = Assert.Single<ApiDescription>(group.Items); |
| 1581 | + |
| 1582 | + var responseType = Assert.Single(apiDescription.SupportedResponseTypes); |
| 1583 | + Assert.Equal(StatusCodes.Status200OK, responseType.StatusCode); |
| 1584 | + Assert.Equal(typeof(Product), responseType.Type); |
| 1585 | + |
| 1586 | + Assert.NotNull(apiDescription.ActionDescriptor.EndpointMetadata); |
| 1587 | + var producesResponseTypeMetadata = apiDescription.ActionDescriptor.EndpointMetadata.OfType<ProducesResponseTypeMetadata>().SingleOrDefault(); |
| 1588 | + Assert.NotNull(producesResponseTypeMetadata); |
| 1589 | + Assert.Equal(StatusCodes.Status200OK, producesResponseTypeMetadata.StatusCode); |
| 1590 | + Assert.Equal(typeof(Product), producesResponseTypeMetadata.Type); |
| 1591 | + } |
| 1592 | + |
1568 | 1593 | private IEnumerable<string> GetSortedMediaTypes(ApiExplorerResponseType apiResponseType) |
1569 | 1594 | { |
1570 | 1595 | return apiResponseType.ResponseFormats |
|
0 commit comments