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)); }
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); }
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); }
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); }
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); }
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); }
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")); }
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")); }
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)); }
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); }