Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.
This repository was archived by the owner on May 19, 2024. It is now read-only.

Fails on WEBApi routes that work in application #50

@btrepp

Description

@btrepp

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

[TestFixture]
 class TestApiRoute
    {
        HttpConfiguration config;
        [SetUp]
        public void Setup()
        {
            RouteAssert.UseAssertEngine(new NunitAssertEngine());
            config = new HttpConfiguration();
            WebApiConfig.Register(config);
            config.EnsureInitialized();
        }

        [Test]
        public void HasResourceApiRoute()
        {
            RouteAssert.HasApiRoute(config, "/api/resource", HttpMethod.Get);
        }
}

WebAPIConfig

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions