Exemplo n.º 1
0
        static AppRoutes()
        {
            var authRoute = new Route(Methods.Get, "/logs", new HttpLibrary.Directors.FileResponse())
            {
                Credentials = new Credentials("admin", "hunter2")
            };
            var redirectRoute = new Route(Methods.Get, "/redirect", new Directors.GetResponse())
            {
                Redirect = "/"
            };

            Routes = new []
            {
                authRoute,
                redirectRoute,
                new Route(Methods.Delete, "/form", new DeleteResponse()),
                new Route(Methods.Get, "/file1", new Directors.GetResponse()),
                new Route(Methods.Get, "/text-file.txt", new Directors.FileResponse()),
                new Route(Methods.Get, "/", new Directors.GetResponse()),
                new Route(Methods.Get, "/partial_content.txt", new Directors.FileResponse()),
                new Route(Methods.Get, "/patch-content.txt", new Directors.GetResponse()),
                new Route(Methods.Patch, "/patch-content.txt", new PatchResponse()),
                new Route(Methods.Get, "/form", new Directors.GetResponse()),
                new Route(Methods.Put, "/form", new PostResponse()),
                new Route(Methods.Post, "/form", new PostResponse()),
                new Route(Methods.Delete, "/form", new DeleteResponse()),
                new Route(Methods.Options, "/method_options", new OptionsResponse())
            };
        }
Exemplo n.º 2
0
 public void ItCanReturnQuoteForm()
 {
     var mRequest = new MockRequest() {Method = "GET", Resource = "/", Route="GET /"};
     var route = new Route("GET", "/", new QuoteFormResponse());
     var routes = new Router();
     routes.AddRoute(route);
     var responseString = routes.GetResponse(mRequest).ToString();
     var expectedResponseString = (new QuoteFormResponse()).Construct(mRequest).ToString();
     responseString.ShouldEqual(expectedResponseString);
 }
Exemplo n.º 3
0
 public void AddRoutes(Route[] routes)
 {
     foreach (var route in routes)
         AddRoute(route);
 }
Exemplo n.º 4
0
 public void AddRoute(Route route)
 {
     UpdateAppRoutes(route);
     UpdateOptions(route);
 }
Exemplo n.º 5
0
 private void UpdateOptions(Route route)
 {
     if (_options.ContainsKey(route.Resource))
         _options[route.Resource] += "," + route.Method;
     else
         _options.Add(route.Resource, route.Method);
 }
Exemplo n.º 6
0
 private void UpdateAppRoutes(Route route)
 {
     if (_appRoutes.ContainsKey(route.Get()))
         _appRoutes[route.Get()] = route;
     else
         _appRoutes.Add(route.Get(), route);
 }
Exemplo n.º 7
0
 private bool UnauthorizedRoute(IRequest request, Route route)
 {
     return route.HasCredentials() && !Authenticator.Verify(route.Credentials, GetRequestCredentials(request));
 }
Exemplo n.º 8
0
 public void AddRoutes(Route[] routes)
 {
     AppRoutes.AddRoutes(routes);
 }
Exemplo n.º 9
0
 public void AddRoute(Route route)
 {
     AppRoutes.AddRoute(route);
 }