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.

"Global" controller routes not respected #56

@justmara

Description

@justmara

Since MVC/WebAPI 5.2 there is an option to add single global route attribute to controller so all the actions in it will match:

    [RoutePrefix("files"), Route("{container}/{id}")]
    public class FilesController : ApiController
    {
        [HttpGet]
        public async Task<IHttpActionResult> GetDescription(string container, string id)
        {
            return Ok();
        }

        [HttpDelete]
        public async Task<IHttpActionResult> Delete(string container, string id)
        {
            return Ok();
        }
    }

This notation actually works flawlessly and all requests land as expected. But test fails:

    [TestMethod]
    public void GetDescription()
    {
        var expectations = new
        {
            controller = "Files",
            action = "GetDescription",
            container = "someContainer",
            id = "someFile"
        };
        RouteAssert.HasApiRoute(_host.Config, "/files/someContainer/someFile", HttpMethod.Get, expectations);
    }

with error: Expected 'someFile', got missing value for 'id' at url '/files/someContainer/someFile'.
Simply copying the route attribute from controller to method declaration makes it pass:

    [HttpGet, Route("{container}/{id}")]
    public async Task<IHttpActionResult> GetDescription(string container, string id)

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