beyond-code-github / Superscribe

A fresh take on URL routing for Web APIs
Apache License 2.0
64 stars 6 forks source link

Route matching ignores HTTP method #3

Open benfoster opened 10 years ago

benfoster commented 10 years ago

As discussed, route matching appears to be ignoring the HTTP method. In the test below the GET route is always hit, even when making a POST.

namespace Superscribe.Tests.Owin
{
    class RoutingTests
    {
        static TestServer owinTestServer;
        static HttpClient client;

        static HttpResponseMessage response;

        Establish context = () =>
        {
            owinTestServer = TestServer.Create(app =>
            {
                var define = OwinRouteEngineFactory.Create();

                define.Get("products", ctx => "Hello");
                define.Post("products", ctx =>
                {
                    ctx.StatusCode = (int)HttpStatusCode.Created;
                    return "Created";
                });

                app.UseSuperscribeRouter(define)
                    .UseSuperscribeHandler(define);
            });

            client = owinTestServer.HttpClient;
            client.DefaultRequestHeaders.Add("accept", "text/html");
        };

        class When_requesting_a_valid_route_with_matching_verb
        {
            Because of = () => response = client.GetAsync("http://localhost/products").Await();

            It Should_return_200 = () =>
            {
                response.StatusCode.ShouldEqual(HttpStatusCode.OK);
            };
        }

        class When_requesting_a_valid_route_different_verb
        {
            Because of = () => response = client.PostAsync("http://localhost/products", new StringContent("test")).Await();

            It Should_not_match_the_route = () =>
            {
                response.StatusCode.ShouldEqual(HttpStatusCode.Created);
            };
        }
    }
}

Also I noticed that a template of products would also match products/add.