Пример #1
0
        public void When_matcher_is_asked_to_return_a_request_handler_that_is_set_up_that_handler_is_returned()
        {
            const string testResponse = "test-response";

            var routeHandlers = new Dictionary <RouteBase, Func <OwinRequest, object> >
            {
                {
                    new RegexRoute("foo/"), r =>
                    {
                        return(testResponse);
                    }
                }
            };

            var matcher = new RouteMatcher(routeHandlers);

            var request = OwinRequest.Create();

            request.Path = "foo/";

            Assert.That(matcher.HasMatch(request), Is.True);
            var handler = matcher.GetMatch(request);

            Assert.That(handler(request).ToString(), Is.EqualTo(testResponse));
        }
Пример #2
0
        private static void AssertPathMatches(RouteMatcher matcher, string path, string expectedResponse)
        {
            var request = OwinRequest.Create();

            request.Path = path;

            var match = matcher.GetMatch(request);

            Assert.That(match(request).ToString(), Is.EqualTo(expectedResponse), "invalid match for path:" + path);
        }
Пример #3
0
        public void When_matcher_is_asked_to_return_a_request_handler_that_is_not_set_up_null_is_returned()
        {
            var matcher = new RouteMatcher(new Dictionary <RouteBase, Func <OwinRequest, object> > {
            });

            var request = OwinRequest.Create();

            request.Path = "foo/";

            Assert.That(matcher.HasMatch(request), Is.False);
            var handler = matcher.GetMatch(request);

            Assert.That(handler, Is.Null);
        }
Пример #4
0
        public void When_matcher_is_asked_to_match_a_request_that_has_many_paths_set_up_the_most_specific_route_which_matches_wins()
        {
            var routeHandlers = new Dictionary <RouteBase, Func <OwinRequest, object> >
            {
                { new RegexRoute("foo/"), r => { return("test-response-default"); } },
                { new RegexRoute("foo/", "GET"), r => { return("test-response-get"); } },
                { new RegexRoute("foo/", "POST"), r => { return("test-response-post"); } }
            };

            var matcher = new RouteMatcher(routeHandlers);

            var request = OwinRequest.Create();

            request.Path   = "foo/";
            request.Method = "POST";

            Assert.That(matcher.HasMatch(request), Is.True);
            Assert.That(matcher.GetMatch(request)(request).ToString(), Is.EqualTo("test-response-post"));
        }
Пример #5
0
        public void When_matcher_is_asked_to_match_a_request_that_has_many_paths_set_up_the_most_specific_route_which_matches_wins()
        {
            var routeHandlers = new Dictionary<RouteBase, Func<OwinRequest, object>>
                                    {
                                        {new RegexRoute("foo/"), r => { return "test-response-default"; }},
                                        {new RegexRoute("foo/", "GET"), r => { return "test-response-get"; }},
                                        {new RegexRoute("foo/", "POST"), r => { return "test-response-post"; }}
                                    };

            var matcher = new RouteMatcher(routeHandlers);

            var request = OwinRequest.Create();
            request.Path = "foo/";
            request.Method = "POST";

            Assert.That(matcher.HasMatch(request), Is.True);
            Assert.That(matcher.GetMatch(request)(request).ToString(), Is.EqualTo("test-response-post"));
        }
Пример #6
0
        private static void AssertPathMatches(RouteMatcher matcher, string path, string expectedResponse)
        {
            var request = OwinRequest.Create();
            request.Path = path;

            var match = matcher.GetMatch(request);
            Assert.That(match(request).ToString(), Is.EqualTo(expectedResponse), "invalid match for path:" + path);
        }
Пример #7
0
        public void When_matcher_is_asked_to_return_a_request_handler_that_is_set_up_that_handler_is_returned()
        {
            const string testResponse = "test-response";

            var routeHandlers = new Dictionary<RouteBase, Func<OwinRequest, object>>
                                    {
                                        {
                                            new RegexRoute("foo/"), r =>
                                                        {
                                                            return testResponse;
                                                        }
                                        }
                                    };

            var matcher = new RouteMatcher(routeHandlers);

            var request = OwinRequest.Create();
            request.Path = "foo/";

            Assert.That(matcher.HasMatch(request), Is.True);
            var handler = matcher.GetMatch(request);
            Assert.That(handler(request).ToString(), Is.EqualTo(testResponse));
        }
Пример #8
0
        public void When_matcher_is_asked_to_return_a_request_handler_that_is_not_set_up_null_is_returned()
        {
            var matcher = new RouteMatcher(new Dictionary<RouteBase, Func<OwinRequest, object>> { });

            var request = OwinRequest.Create();
            request.Path = "foo/";

            Assert.That(matcher.HasMatch(request), Is.False);
            var handler = matcher.GetMatch(request);
            Assert.That(handler, Is.Null);
        }