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

Fails on similar routes with different parameter names #57

Closed justmara closed 9 years ago

justmara commented 9 years ago
    [RoutePrefix("test")]
    public class TestController : ApiController
    {
        [HttpGet, Route("{container}/{id}")]
        public async Task<IHttpActionResult> Get(string container, string id)
        {
            return Ok();
        }

        [HttpPost, Route("{container}/{user}")]
        public async Task<IHttpActionResult> Add(string container, string user)
        {
            return Ok();
        }
    }

So here is GET with id and POST with user second parameter names.

    [TestMethod]
    public void TestGet()
    {
        var expectations = new
        {
            controller = "Test",
            action = "Get",
            container = "someContainer",
            id = "someId"
        };
        RouteAssert.HasApiRoute(_host.Config, "/test/someContainer/someId", HttpMethod.Get, expectations);
    }

    [TestMethod]
    public void TestAddFail()
    {
        var expectations = new
        {
            controller = "Test",
            action = "Add",
            container = "someContainer",
            user = "someUser"
        };
        RouteAssert.HasApiRoute(_host.Config, "/test/someContainer/someUser", HttpMethod.Post, expectations);
    }

The Add fails with Expected 'someUser', got missing value for 'user' at url '/test/someContainer/someUser'.