AnthonySteele / MvcRouteTester

A library for unit testing ASP MVC route tables for both Web and API Routes
Apache License 2.0
105 stars 43 forks source link

One route, different Actionnames #35

Open ledux opened 10 years ago

ledux commented 10 years ago

I got one Route, which maps three Actions in one API-Controller:

        configuration.Routes.MapHttpRoute(
            name: "kontext",
            routeTemplate: "pabsapi/leistungserfassung/{maid}/{firmId}",
            defaults: new 
            { 
                controller = Routing.KONTEXT, 
                maid = RouteParameter.Optional,
                firmId = RouteParameter.Optional
            });

The Actions:

    [HttpGet]
    public ILeKontext GetKontext()
    {
        string maid = ExtractUsername();
        ILeKontext kontext = _repo.GetKontext(maid);

        return kontext;
    }

    [HttpGet]
    public IPabsMitarbeiter GetMitarbeiter(string maid)
    {
        IPabsMitarbeiter mitarbeiter = _repo.GetMitarbeiter(maid);

        return mitarbeiter;
    }

    [HttpGet]
    public IFirmaRoute GetFirmRoute(string maid, int firmId)
    {
        IFirmaRoute route = _repo.GetRoute(maid, firmId);

        return route;
    }

Unfortunately MvcRouteTester always maps to the Action GetFirmRoute(maid, firmId)

        private static HttpConfiguration _routes = new HttpConfiguration();
        ApiRouteConfig.Register(_routes);
        _routes.ShouldMap("/pabsapi/leistungserfassung").To<KontextController>(HttpMethod.Get, c => c.GetKontext());
        _routes.ShouldMap("/pabsapi/leistungserfassung/lt").To<KontextController>(HttpMethod.Get, c => c.GetMitarbeiter("lt"));
        _routes.ShouldMap("/pabsapi/leistungserfassung/lt/1").To<KontextController>(HttpMethod.Get, c => c.GetFirmRoute("lt", 1));

Only the last ShouldMap passes the test.

If I change every Actionname to Get, everything works fine.

Is there a way, to have different Actionnames in the same route?