Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to register routes for Testing WebApi routes (WebApiContrib.Testing)? #128

Open
romka-04 opened this issue Dec 3, 2015 · 0 comments

Comments

@romka-04
Copy link

romka-04 commented Dec 3, 2015

Probably this topic was described before but I could not find a solution.

There are two ways to registrate routes in MVC and WebApi projects:

  1. MVC Project you call RouteConfig.RegisterRoutes( RouteTable.Routes ) which adds routes into routes table. This way is used in your example (here: http://www.carolynvanslyck.com/blog/2013/01/webapi-route-testing/)
  2. WebApi Project by default use GlobalConfiguration.Configure( WebApiConfig.Register ). The following example shows how to register routes in unit tests file.
private HttpConfiguration _config;
[SetUp]
public void BeforeEach()
{
    _config = new HttpConfiguration();
    WebApiConfig.Register( _config );
    _config.EnsureInitialized();  // we need to call this method after all other initialization code.
}

The problem that your framework is using RouteTable to check routes. If I register routes in second way then RouteTable would be empty and route tests also would fails.

Could you please provide some link or explanation how to register WebApi routes without moving code into RouteTable.Routes method?
I'm not sure that you understand me so please ask a questions if you want.
Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant