@@ -1243,6 +1243,45 @@ public void CreateActionModel_InheritedAttributeRoutesOverridden()
12431243 Assert . Contains ( selectorModel . AttributeRouteModel . Attribute , action . Attributes ) ;
12441244 }
12451245
1246+ [ Fact ]
1247+ public void CreateActionModel_PopulatesReturnTypeEndpointMetadata ( ) {
1248+ // Arrange
1249+ var builder = new TestApplicationModelProvider ( ) ;
1250+ var typeInfo = typeof ( TypedResultsReturningActionsController ) . GetTypeInfo ( ) ;
1251+ var actionName = nameof ( TypedResultsReturningActionsController . Get ) ;
1252+
1253+ // Act
1254+ var action = builder . CreateActionModel ( typeInfo , typeInfo . AsType ( ) . GetMethod ( actionName ) ) ;
1255+
1256+ // Assert
1257+ Assert . NotNull ( action . Selectors ) ;
1258+ Assert . All ( action . Selectors , selector =>
1259+ {
1260+ Assert . NotNull ( selector . EndpointMetadata ) ;
1261+ Assert . Contains ( selector . EndpointMetadata , m => m is ProducesResponseTypeMetadata ) ;
1262+ } ) ;
1263+ var metadata = action . Selectors [ 0 ] . EndpointMetadata . OfType < ProducesResponseTypeMetadata > ( ) . Single ( ) ;
1264+ Assert . Equal ( 200 , metadata . StatusCode ) ;
1265+ }
1266+
1267+ [ Fact ]
1268+ public void AddReturnTypeMetadata_ExtractsMetadataFromReturnType ( )
1269+ {
1270+ // Arrange
1271+ var selector = new SelectorModel ( ) ;
1272+ var selectors = new List < SelectorModel > { selector } ;
1273+ var actionMethod = typeof ( TypedResultsReturningActionsController ) . GetMethod ( nameof ( TypedResultsReturningActionsController . Get ) ) ;
1274+
1275+ // Act
1276+ DefaultApplicationModelProvider . AddReturnTypeMetadata ( selectors , actionMethod ) ;
1277+
1278+ // Assert
1279+ Assert . NotNull ( selector . EndpointMetadata ) ;
1280+ Assert . Single ( selector . EndpointMetadata ) ;
1281+ Assert . IsType < ProducesResponseTypeMetadata > ( selector . EndpointMetadata . Single ( ) ) ;
1282+ Assert . Equal ( 200 , ( ( ProducesResponseTypeMetadata ) selector . EndpointMetadata [ 0 ] ) . StatusCode ) ;
1283+ }
1284+
12461285 [ Fact ]
12471286 public void ControllerDispose_ExplicitlyImplemented_IDisposableMethods_AreTreatedAs_NonActions ( )
12481287 {
@@ -1711,6 +1750,16 @@ public void Details() { }
17111750 public void List ( ) { }
17121751 }
17131752
1753+ private class TypedResultsReturningActionsController : Controller
1754+ {
1755+ [ HttpGet ]
1756+ public Http . HttpResults . Ok < Foo > Get ( ) => TypedResults . Ok < Foo > ( new Foo { Info = "Hello" } ) ;
1757+ }
1758+
1759+ public class Foo {
1760+ public required string Info { get ; set ; }
1761+ }
1762+
17141763 private class CustomHttpMethodsAttribute : Attribute , IActionHttpMethodProvider
17151764 {
17161765 private readonly string [ ] _methods ;
0 commit comments