¿Cómo realizar correctamente la prueba unitaria del controlador OData v6.0?

Estoy intentando probar por unidad los controladores OData, sin embargo, las API cambiaron y los métodos recomendados anteriormente que probé no funcionan.

No hay ruta HTTP no-OData registrada.

al intentar crear una instancia de ODataQueryOptions para pasar al método Get del controlador

Mi código actual (basado en respuestas como esta ):

[TestMethod()] public void RankingTest() { var serviceMock = new Mock(); serviceMock.SetReturnsDefault<IEnumerable>(new List() { new Vendor() { id = "1" } }); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/odata/Vendor"); ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet("Vendor"); var model = builder.GetEdmModel(); HttpRouteCollection routes = new HttpRouteCollection(); HttpConfiguration config = new HttpConfiguration(routes) { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; // attempting to register at least some non-OData HTTP route doesn't seem to help routes.MapHttpRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); config.MapODataServiceRoute("odata", "odata", model); config.Count().Filter().OrderBy().Expand().Select().MaxTop(null); config.EnsureInitialized(); request.SetConfiguration(config); ODataQueryContext context = new ODataQueryContext( model, typeof(Vendor), new ODataPath( new Microsoft.OData.UriParser.EntitySetSegment( model.EntityContainer.FindEntitySet("Vendor")) ) ); var controller = new VendorController(serviceMock.Object); controller.Request = request; // InvalidOperationException in System.Web.OData on next line: // No non-OData HTTP route registered var options = new ODataQueryOptions(context, request); var response = controller.Get(options) as ViewResult; } 

Gracias por cualquier idea o punteros!

Agregue una llamada al método EnableDependencyInjection desde la clase System.Web.OData.Extensions.HttpConfigurationExtensions :

 HttpConfiguration config = new HttpConfiguration(); //1 config.EnableDependencyInjection(); //2 config.EnsureInitialized();