Open btrepp opened 10 years ago
I have the same problem. Could you please suggest me how can I solve it?
@Marusyk I have moved away from testing routes. Currently I use the OWIN framework, so I'm using the OWIN test server and mocking out service layer things (by using a dummy startup.cs). This is how I verify I have routes and that serialization is working correctly in WebApi.
It's super heavy, but it's the only reliable solution I have found to verify that that part of webapi/mvc actually works correctly via tests!
Some time I want to look at this, and re-do it in vNext. I hope that ASP MVC vNext will offer a way to make a http request testing library that isn't either heavyweight and black-box, or fragile and hacky like this lib. But I don't know enough about vNext yet.
I think you are trying to reinvent the wheel with model binding with your own algorithm. You can let the Web API framework do the heavy lifting for you. I have implemented a route testing in one of my projects. You can take a look, more specifically in the GetActionContext method where you make the Web API do the model binding for you, depending on the request headers: https://github.com/ivaylokenov/MyWebApi/blob/master/src/MyWebApi/Utilities/RouteResolvers/InternalRouteResolver.cs
It's true that this code is reaching its limits. But so are the internals of ASP.Net that it works with- vNext will change all of this.
I have a Web project and a Test Project. I'm using webapi in the web project and MVCRoute tester in the second.
Test is
WebAPIConfig
This test fails with
Route with controller not found for url 'http://site.com/api/resource'
but if I run the project the route/controller work fine.Obviously I done the setup incorrect, but I'm not sure where, and the documentation isn't very clear on how you should setup 'config'