コード例 #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
        public void When_matcher_is_asked_to_match_a_path_that_is_not_set_up_no_match_is_found()
        {
            var routeHandlers = new Dictionary<RouteBase, Func<OwinRequest, object>>();

            var matcher = new RouteMatcher(routeHandlers);

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

            Assert.That(matcher.HasMatch(request), Is.False);
        }
コード例 #3
0
        public void When_matcher_is_asked_to_match_a_path_that_is_set_up_match_is_found()
        {
            var routeHandlers = new Dictionary<RouteBase, Func<OwinRequest, object>>();
            routeHandlers.Add(new RegexRoute("foo/"), r => { return "test-response"; });

            var matcher = new RouteMatcher(routeHandlers);

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

            Assert.That(matcher.HasMatch(request), Is.True);
        }
コード例 #4
0
        public void When_matcher_is_asked_to_match_a_path_that_is_not_set_up_no_match_is_found()
        {
            var routeHandlers = new Dictionary <RouteBase, Func <OwinRequest, object> >();

            var matcher = new RouteMatcher(routeHandlers);

            var request = OwinRequest.Create();

            request.Path = "foo/";

            Assert.That(matcher.HasMatch(request), Is.False);
        }
コード例 #5
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);
        }
コード例 #6
0
        public void When_matcher_is_asked_to_match_a_path_that_is_set_up_match_is_found()
        {
            var routeHandlers = new Dictionary <RouteBase, Func <OwinRequest, object> >();

            routeHandlers.Add(new RegexRoute("foo/"), r => { return("test-response"); });

            var matcher = new RouteMatcher(routeHandlers);

            var request = OwinRequest.Create();

            request.Path = "foo/";

            Assert.That(matcher.HasMatch(request), Is.True);
        }
コード例 #7
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"));
        }
コード例 #8
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"));
        }
コード例 #9
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));
        }
コード例 #10
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);
        }