11namespace System . Web . OData
22{
3- using FluentAssertions ;
43 using Batch ;
54 using Builder ;
65 using Collections . Generic ;
7- using Collections . ObjectModel ;
6+ using FluentAssertions ;
87 using Http ;
9- using Http . Controllers ;
108 using Http . Dispatcher ;
119 using Linq ;
1210 using Microsoft . OData . Edm ;
1917
2018 public class HttpConfigurationExtensionsTest
2119 {
20+ [ ApiVersion ( "1.0" ) ]
21+ private sealed class ControllerV1 : ODataController
22+ {
23+ }
24+
25+ [ ApiVersion ( "2.0" ) ]
26+ private sealed class ControllerV2 : ODataController
27+ {
28+ }
29+
2230 private static IEnumerable < IEdmModel > CreateModels ( HttpConfiguration configuration )
2331 {
24- var controllerDescriptor = new Mock < HttpControllerDescriptor > ( configuration , "Test" , typeof ( IHttpController ) ) { CallBase = true } ;
25- var controllerMapping = new Dictionary < string , HttpControllerDescriptor > ( ) { { "Test" , controllerDescriptor . Object } } ;
26- var controllerSelector = new Mock < IHttpControllerSelector > ( ) ;
27- var apiVersions = new Collection < ApiVersionAttribute > ( new [ ] { new ApiVersionAttribute ( "1.0" ) , new ApiVersionAttribute ( "2.0" ) } ) ;
28- var builder = new VersionedODataModelBuilder ( controllerSelector . Object ) ;
32+ var controllerTypeResolver = new Mock < IHttpControllerTypeResolver > ( ) ;
33+ var controllerTypes = new List < Type > ( ) { typeof ( ControllerV1 ) , typeof ( ControllerV2 ) } ;
34+
35+ controllerTypeResolver . Setup ( ctr => ctr . GetControllerTypes ( It . IsAny < IAssembliesResolver > ( ) ) ) . Returns ( controllerTypes ) ;
36+ configuration . Services . Replace ( typeof ( IHttpControllerTypeResolver ) , controllerTypeResolver . Object ) ;
2937
30- controllerDescriptor . Setup ( cd => cd . GetCustomAttributes < ApiVersionAttribute > ( It . IsAny < bool > ( ) ) ) . Returns ( apiVersions ) ;
31- controllerSelector . Setup ( cs => cs . GetControllerMapping ( ) ) . Returns ( controllerMapping ) ;
38+ var builder = new VersionedODataModelBuilder ( configuration ) ;
3239
3340 return builder . GetEdmModels ( ) ;
3441 }
@@ -51,7 +58,7 @@ public void map_versioned_odata_routes_should_return_expected_result()
5158 var batchRoute = configuration . Routes [ "odataBatch" ] ;
5259
5360 // assert
54- constraint . RoutingConventions [ 0 ] . Should ( ) . BeOfType < AttributeRoutingConvention > ( ) ;
61+ constraint . RoutingConventions [ 0 ] . Should ( ) . BeOfType < VersionedAttributeRoutingConvention > ( ) ;
5562 constraint . RoutingConventions [ 1 ] . Should ( ) . BeOfType < VersionedMetadataRoutingConvention > ( ) ;
5663 constraint . RoutingConventions . OfType < MetadataRoutingConvention > ( ) . Should ( ) . BeEmpty ( ) ;
5764 constraint . RouteName . Should ( ) . Be ( routeName ) ;
@@ -82,7 +89,7 @@ public void map_versioned_odata_routes_should_return_expected_results()
8289 var apiVersion = constraint . EdmModel . GetAnnotationValue < ApiVersionAnnotation > ( constraint . EdmModel ) . ApiVersion ;
8390 var versionedRouteName = routeName + "-" + apiVersion . ToString ( ) ;
8491
85- constraint . RoutingConventions [ 0 ] . Should ( ) . BeOfType < AttributeRoutingConvention > ( ) ;
92+ constraint . RoutingConventions [ 0 ] . Should ( ) . BeOfType < VersionedAttributeRoutingConvention > ( ) ;
8693 constraint . RoutingConventions [ 1 ] . Should ( ) . BeOfType < VersionedMetadataRoutingConvention > ( ) ;
8794 constraint . RoutingConventions . OfType < MetadataRoutingConvention > ( ) . Should ( ) . BeEmpty ( ) ;
8895 constraint . RouteName . Should ( ) . Be ( versionedRouteName ) ;
0 commit comments