@@ -115,6 +115,7 @@ public void AppliesToActionWithLongTemplateWorksAsExpected()
115
115
// Assert
116
116
SelectorModel actualSelectorModel = Assert . Single ( action . Selectors ) ;
117
117
Assert . Equal ( "/Customers({key})/Orders({relatedKey})/NS.MyOrder/Title" , actualSelectorModel . AttributeRouteModel . Template ) ;
118
+ Assert . Null ( actualSelectorModel . AttributeRouteModel . Order ) ;
118
119
Assert . Contains ( actualSelectorModel . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
119
120
}
120
121
@@ -144,21 +145,74 @@ public void AppliesToActionWithRoutePrefixWorksAsExpected()
144
145
e =>
145
146
{
146
147
Assert . Equal ( "/Customers/{key}" , e . AttributeRouteModel . Template ) ;
148
+ Assert . Equal ( 9 , e . AttributeRouteModel . Order ) ;
147
149
Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
148
150
} ,
149
151
e =>
150
152
{
151
153
Assert . Equal ( "/Orders/{key}" , e . AttributeRouteModel . Template ) ;
154
+ Assert . Equal ( 9 , e . AttributeRouteModel . Order ) ;
152
155
Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
153
156
} ,
154
157
e =>
155
158
{
156
159
Assert . Equal ( "/Customers" , e . AttributeRouteModel . Template ) ;
160
+ Assert . Equal ( 3 , e . AttributeRouteModel . Order ) ;
157
161
Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
158
162
} ,
159
163
e =>
160
164
{
161
165
Assert . Equal ( "/Orders" , e . AttributeRouteModel . Template ) ;
166
+ Assert . Equal ( 3 , e . AttributeRouteModel . Order ) ;
167
+ Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
168
+ } ) ;
169
+ }
170
+
171
+ [ Fact ]
172
+ public void AppliesToActionWithOrderOnControllerRoutePrefixWorksAsExpected ( )
173
+ {
174
+ // Arrange
175
+ ControllerModel controller = ControllerModelHelpers . BuildControllerModel < WithPrefixController2 > ( "List" ) ;
176
+ ActionModel action = controller . Actions . First ( ) ;
177
+ Assert . Equal ( 2 , action . Selectors . Count ) ;
178
+
179
+ ODataControllerActionContext context = new ODataControllerActionContext ( string . Empty , _edmModel , controller )
180
+ {
181
+ Action = action ,
182
+ Options = _options ,
183
+ } ;
184
+
185
+ AttributeRoutingConvention attributeConvention = CreateConvention ( ) ;
186
+
187
+ // Act
188
+ bool ok = _attributeConvention . AppliesToAction ( context ) ;
189
+ Assert . False ( ok ) ;
190
+
191
+ // Assert
192
+ Assert . Equal ( 4 , action . Selectors . Count ) ;
193
+ Assert . Collection ( action . Selectors ,
194
+ e =>
195
+ {
196
+ Assert . Equal ( "/Customers/{key}" , e . AttributeRouteModel . Template ) ;
197
+ Assert . Equal ( 9 , e . AttributeRouteModel . Order ) ; // Order from controller
198
+ Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
199
+ } ,
200
+ e =>
201
+ {
202
+ Assert . Equal ( "/Orders/{key}" , e . AttributeRouteModel . Template ) ;
203
+ Assert . Equal ( 8 , e . AttributeRouteModel . Order ) ; // Order from controller
204
+ Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
205
+ } ,
206
+ e =>
207
+ {
208
+ Assert . Equal ( "/Customers" , e . AttributeRouteModel . Template ) ;
209
+ Assert . Equal ( 3 , e . AttributeRouteModel . Order ) ; // Order from action
210
+ Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
211
+ } ,
212
+ e =>
213
+ {
214
+ Assert . Equal ( "/Orders" , e . AttributeRouteModel . Template ) ;
215
+ Assert . Equal ( 3 , e . AttributeRouteModel . Order ) ; // Order from action
162
216
Assert . Contains ( e . EndpointMetadata , a => a is ODataRoutingMetadata ) ;
163
217
} ) ;
164
218
}
@@ -284,13 +338,25 @@ public void LongAction()
284
338
[ Route ( "Orders" ) ]
285
339
private class WithPrefixController
286
340
{
287
- [ HttpGet ( "{key}" ) ]
288
- [ HttpPost ( "" ) ]
341
+ [ HttpGet ( "{key}" , Order = 9 ) ]
342
+ [ HttpPost ( "" , Order = 3 ) ]
289
343
public void List ( int key )
290
344
{
291
345
}
292
346
}
293
347
348
+ [ ODataAttributeRouting ] // using this attribute if not derived from ODataController
349
+ [ Route ( "Customers" , Order = 9 ) ]
350
+ [ Route ( "Orders" , Order = 8 ) ]
351
+ private class WithPrefixController2
352
+ {
353
+ [ HttpGet ( "{key}" ) ]
354
+ [ HttpPost ( "" , Order = 3 ) ] // 3 should override 8 on controller
355
+ public void List ( )
356
+ {
357
+ }
358
+ }
359
+
294
360
[ Route ( "VipCustomer" ) ]
295
361
public class SingletonTestControllerWithPrefix
296
362
{
0 commit comments