Ich bin versucht zu Unit-Test aus OData-Controller, aber die APIs geändert und zuvor Methoden empfohlen habe ich versucht, nicht funktionieren - zur Zeit erhalte ichWie wird der OData v6.0-Controller richtig verbunden?
Keine Nicht-OData HTTP Route registriert.
für alle Ideen oder Hinweise[TestMethod()] public void RankingTest() { var serviceMock = new Mock<IVendorService>(); serviceMock.SetReturnsDefault<IEnumerable<Vendor>>(new List<Vendor>() { new Vendor() { id = "1" } }); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/odata/Vendor"); ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Vendor>("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<Vendor>(context, request); var response = controller.Get(options) as ViewResult; }
Danke:
bei dem Versuch, ODataQueryOptions zu instanziiert in die Get-Methode des Controllers
Mein aktueller Code (basierend auf Antworten wie this one) zu übergeben!
Danke, die es getan zu haben scheint! – kerray