@@ -93,6 +93,71 @@ public void InferParameterBindingSources_Throws_IfMultipleParametersAreFromBody(
9393 Assert . Equal ( expected , ex . Message ) ;
9494 }
9595
96+ [ Fact ]
97+ public void InferParameterBindingSources_InfersSources ( )
98+ {
99+ // Arrange
100+ var actionName = nameof ( ParameterBindingController . ComplexTypeModelWithCancellationToken ) ;
101+ var modelMetadataProvider = TestModelMetadataProvider . CreateDefaultProvider ( ) ;
102+ var convention = GetConvention ( modelMetadataProvider ) ;
103+ var action = GetActionModel ( typeof ( ParameterBindingController ) , actionName , modelMetadataProvider ) ;
104+
105+ // Act
106+ convention . InferParameterBindingSources ( action ) ;
107+
108+ // Assert
109+ Assert . Collection (
110+ action . Parameters ,
111+ parameter =>
112+ {
113+ Assert . Equal ( "model" , parameter . Name ) ;
114+
115+ var bindingInfo = parameter . BindingInfo ;
116+ Assert . NotNull ( bindingInfo ) ;
117+ Assert . Same ( BindingSource . Body , bindingInfo . BindingSource ) ;
118+ } ,
119+ parameter =>
120+ {
121+ Assert . Equal ( "cancellationToken" , parameter . Name ) ;
122+
123+ var bindingInfo = parameter . BindingInfo ;
124+ Assert . NotNull ( bindingInfo ) ;
125+ Assert . Equal ( BindingSource . Special , bindingInfo . BindingSource ) ;
126+ } ) ;
127+ }
128+
129+ [ Fact ]
130+ public void InferParameterBindingSources_DoesNotInferSources_IfSuppressInferBindingSourcesForParametersIsSet ( )
131+ {
132+ // Arrange
133+ var actionName = nameof ( ParameterBindingController . ComplexTypeModelWithCancellationToken ) ;
134+ var modelMetadataProvider = TestModelMetadataProvider . CreateDefaultProvider ( ) ;
135+ var convention = GetConvention ( modelMetadataProvider ) ;
136+ var action = GetActionModel ( typeof ( ParameterBindingController ) , actionName , modelMetadataProvider ) ;
137+
138+ convention . SuppressInferBindingSourcesForParameters = true ;
139+
140+ // Act
141+ convention . InferParameterBindingSources ( action ) ;
142+
143+ // Assert
144+ Assert . Collection (
145+ action . Parameters ,
146+ parameter =>
147+ {
148+ Assert . Equal ( "model" , parameter . Name ) ;
149+ Assert . Null ( parameter . BindingInfo ) ;
150+ } ,
151+ parameter =>
152+ {
153+ Assert . Equal ( "cancellationToken" , parameter . Name ) ;
154+
155+ var bindingInfo = parameter . BindingInfo ;
156+ Assert . NotNull ( bindingInfo ) ;
157+ Assert . Equal ( BindingSource . Special , bindingInfo . BindingSource ) ;
158+ } ) ;
159+ }
160+
96161 [ Fact ]
97162 public void Apply_PreservesBindingInfo_WhenInferringFor_ParameterWithModelBinder_AndExplicitName ( )
98163 {
0 commit comments