public static void MapPagesToControlOfSameName(this SubtextRouteMapper routes, params string[] controlNames)
 {
     foreach (var controlName in controlNames)
     {
         routes.MapPageToControl(controlName);
     }
 }
 /// <summary>
 /// We need special handling here because of Aggregate blogs.
 /// </summary>
 /// <param name="routes"></param>
 public static void MapRoot(this SubtextRouteMapper routes)
 {
     routes.Add("root",
                new RootRoute(
                    String.Equals(ConfigurationManager.AppSettings["AggregateEnabled"], "true",
                                  StringComparison.OrdinalIgnoreCase), routes.ServiceLocator));
 }
 public static void MapSystemDirectories(this SubtextRouteMapper routes, params string[] directoryNames)
 {
     foreach (var directoryName in directoryNames)
     {
         routes.MapSystemDirectory(directoryName);
     }
 }
        public static void MapSystemPage(this SubtextRouteMapper routes, string name)
        {
            string url = string.Format("{0}.aspx", name);

            routes.Add(name,
                       new Route(url,
                                 new PageRouteHandler(string.Format("~/aspx/{0}", url), routes.ServiceLocator.GetService <ISubtextPageBuilder>(),
                                                      routes.ServiceLocator)));
        }
 public static void MapRoute(this SubtextRouteMapper routes, string routeName, string url, object defaults,
                             object constraints)
 {
     routes.Add(routeName, new SubtextRoute(url, new MvcRouteHandler())
     {
         Defaults    = ToRouteValueDictionary(defaults),
         Constraints = ToRouteValueDictionary(constraints)
     });
 }
        public static void MapHttpHandler <THttpHandler>(this SubtextRouteMapper routes, string name, string url,
                                                         object constraints) where THttpHandler : IHttpHandler
        {
            var route = new SubtextRoute(url, new HttpRouteHandler <THttpHandler>(routes.ServiceLocator))
            {
                Constraints = ToRouteValueDictionary(constraints)
            };

            routes.Add(name, route);
        }
        public void MapControls_WithoutConstraints_AddsPageRouteWithConstraintsToCollection()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);

            //act
            subtextRoutes.MapControls("url", new[] {"controls"});

            //assert
            Assert.AreEqual("url", ((PageRoute)routes[0]).Url);
        }
Example #8
0
        public void MapControls_WithConstraints_AddsPageRouteWithConstraintsToCollection()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);

            //act
            subtextRoutes.MapControls("url", new { constraint = "constraintvalue" }, new[] { "controls" });

            //assert
            Assert.AreEqual("constraintvalue", ((PageRoute)routes[0]).Constraints["constraint"]);
        }
        public void Ignore_AddsIgnoreRoute_ToRouteCollection()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);

            //act
            subtextRoutes.Ignore("url");

            //assert
            Assert.AreEqual(typeof(IgnoreRoute), routes[0].GetType());
        }
        public static void MapControls(this SubtextRouteMapper routes, string name, string url,
                                       RouteValueDictionary constraints, IEnumerable <string> controls, RouteValueDictionary defaults)
        {
            var pageRoute =
                new PageRoute(url, "~/aspx/Dtp.aspx", controls, routes.ServiceLocator)
            {
                Constraints = constraints,
                Defaults    = defaults
            };

            routes.Add(name, pageRoute);
        }
        public void MapSystemDirectory_SetsDirectoryRouteHandlerAndAddsPathInfoToRouteUrl()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);

            //act
            subtextRoutes.MapSystemDirectory("install");

            //assert
            var route = routes[0] as Route;
            Assert.AreEqual("install/{*pathInfo}", route.Url);
            Assert.AreEqual(typeof(DirectoryRouteHandler), route.RouteHandler.GetType());
        }
Example #12
0
        public void RequestUrlWithSingleDigitMonth_ForBlogPost_DoesNotMatchPageRoute()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/2008/1/10/blog-post.aspx");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNull(routeData);
        }
Example #13
0
        public void RequestWithoutSubfolderForInstallDirectory_Matches()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/install/default.aspx", "");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNotNull(routeData);
        }
Example #14
0
        public void GetRouteData_ForRequestForExportController_Matches()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/admin/export.ashx", "");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNotNull(routeData);
            Assert.AreEqual("export", routeData.Values["controller"]);
            Assert.AreEqual("blogml", routeData.Values["action"]);
        }
Example #15
0
        public void GetRouteData_ForRequestForEntryAdminController_Matches()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/admin/comments/destroy.ashx", "");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNotNull(routeData);
            Assert.AreEqual("comment", routeData.Values["controller"]);
            Assert.AreEqual("destroy", routeData.Values["action"]);
        }
Example #16
0
 private static AdminUrlHelper SetupUrlHelper(string appPath, RouteData routeData)
 {
     var routes = new RouteCollection();
     var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
     Routes.RegisterRoutes(subtextRoutes);
     var httpContext = new Mock<HttpContextBase>();
     httpContext.Setup(c => c.Request.ApplicationPath).Returns(appPath);
     httpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);
     var requestContext = new RequestContext(httpContext.Object, routeData);
     var helper = new BlogUrlHelper(requestContext, routes);
     return new AdminUrlHelper(helper);
 }
Example #17
0
        public virtual void StartApplication(SubtextRouteMapper routes, HttpServerUtilityBase server)
        {
            Routes.RegisterRoutes(routes);

            var deprecatedPaths = new[]
            {
                "~/Admin", "~/HostAdmin", "~/Install",
                "~/SystemMessages", "~/AggDefault.aspx", "~/DTP.aspx",
                "~/ForgotPassword.aspx", "~/login.aspx", "~/logout.aspx", "~/MainFeed.aspx"
            };
            var invalidPaths =
                from path in deprecatedPaths
                where Directory.Exists(server.MapPath(path)) || File.Exists(server.MapPath(path))
                select path;
            DeprecatedPhysicalPaths = new ReadOnlyCollection<string>(invalidPaths.ToList());
        }
Example #18
0
        public void Request_ForBlogPost_ContainsControlsForBlogPost()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/2008/12/10/blog-post.aspx");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);
            var controls = routeData.DataTokens["controls"] as IEnumerable<string>;
            //assert.

            Assert.IsTrue(controls.Contains("viewpost"));
            Assert.IsTrue(controls.Contains("comments"));
            Assert.IsTrue(controls.Contains("postcomment"));
            Assert.AreEqual("blog-post", routeData.Values["slug"]);
        }
Example #19
0
        public void RequestWithSubfolderForBlogRoot_WithBlogHavingDifferentSubfolder_DoesNotMatch()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/admin/foo.aspx", "not-subfolder");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNull(routeData);
        }
Example #20
0
    public static void RegisterRoutes(SubtextRouteMapper routes)
    {
        routes.MapControls("entry-by-id",
                   "archive/{year}/{month}/{day}/{id}.aspx"
                   ,
                   new
                   {
                       year = @"[1-9]\d{3}",
                       month = @"(0\d)|(1[0-2])",
                       day = @"([0-2]\d)|(3[0-1])",
                       id = @"\d+"
                   }
                   , new[] { "viewpost", "comments", "postcomment" });

        routes.MapControls("entry-by-slug",
                           "archive/{year}/{month}/{day}/{slug}.aspx"
                           , new { year = @"[1-9]\d{3}", month = @"(0\d)|(1[0-2])", day = @"([0-2]\d)|(3[0-1])" }
                           , new[] { "viewpost", "comments", "postcomment" });

        routes.MapRoot();
        routes.MapRoute("skins-admin", "admin/skins/{action}/{id}", new { controller = "skins", id = UrlParameter.Optional });
        routes.MapRoute("comments-admin", "admin/comments/{action}.ashx", new { controller = "comment" });
        routes.Ignore("{resource}.axd/{*pathInfo}");
        routes.Ignore("skins/{*pathInfo}");
        routes.MapSystemPage("MainFeed");
        routes.MapSystemDirectories("hostadmin", "install", "SystemMessages");

        //TODO: Consider making this a single route with a constraint of the allowed pages.
        routes.MapPage("forgotpassword");
        routes.MapPage("login");

        routes.MapHttpHandler<AjaxServices>("ajax-services", "admin/Services/Ajax/AjaxServices.ashx");
        routes.MapHttpHandler<RssAdminHandler>("admin-rss", "admin/{feedName}Rss.axd");
        routes.MapRoute("export", "admin/export.ashx", new { controller = "export", action = "blogml" });
        routes.MapRoute("wlwmanifest", "wlwmanifest.xml.ashx", new { controller = "manifest", action = "index" });
        routes.MapRoute("opensearchdesc", "opensearchdesc.xml.ashx", new { controller = "opensearch", action = "index" });
        routes.MapDirectory("admin");
        routes.MapDirectory("providers");

        routes.MapHttpHandler<SiteMapHttpHandler>("sitemap.ashx");
        routes.MapHttpHandler<BrowserDetectionService>("BrowserServices.ashx");

        //Todo: Add a data token to indicate feed title.
        // By default, the main feed is RSS. To chang it to atom, just
        // swap the route names.
        routes.MapHttpHandler<RssHandler>("rss", "rss.aspx");
        routes.MapHttpHandler<AtomHandler>("atom", "atom.aspx");
        routes.MapHttpHandler<RssCommentHandler>("comment-rss", "comments/commentRss/{id}.aspx");
        routes.MapRoute("comment-api", "comments/{id}.aspx", new { controller = "CommentApi", action = "Create" },
                        new { id = @"\d+" });
        routes.MapRoute("aggbug", "aggbug/{id}.aspx", new { controller = "Statistics", action = "RecordAggregatorView" },
                        new { id = @"\d+" });
        routes.MapHttpHandler<RsdHandler>("rsd", "rsd.xml.ashx");
        routes.MapHttpHandler<BlogSecondaryCssHandler>("customcss", "customcss.aspx");
        //TODO: routes.MapHttpHandler<CategoryRedirectHandler>("category-redirect", "category/{category}.aspx/rss", new { category = @"\d+" });
        routes.MapHttpHandler<RssCategoryHandler>("category-rss", "category/{slug}/rss",
                                                  new { slug = @"[-\w\s\d]+" });
        routes.MapHttpHandler<OpmlHandler>("opml", "opml.xml.ashx");

        routes.MapPagesToControlOfSameName("contact", "ArchivePostPage", "ArticleCategories", "search");

        routes.MapControls("archives", "archives.aspx", null, new[] { "ArchivesPage" });

        routes.MapControls("entries-by-day", "archive/{year}/{month}/{day}.aspx"
                           , new { year = @"[1-9]\d{3}", month = @"(0\d)|(1[0-2])", day = @"([0-2]\d)|(3[0-1])" }
                           , new[] { "ArchiveDay" });

        routes.MapControls("entries-by-month",
                           "archive/{year}/{month}.aspx"
                           , new { year = @"[1-9]\d{3}", month = @"(0\d)|(1[0-2])" }
                           , new[] { "ArchiveMonth" });

        routes.MapControls("article-by-id", "articles/{id}.aspx"
                           , new { id = @"\d+" }
                           , new[] { "viewpost", "comments", "postcomment" });

        routes.MapControls("article-by-slug", "articles/{slug}.aspx"
                           , null
                           , new[] { "viewpost", "comments", "postcomment" });

        routes.MapControls("gallery", "gallery/{id}.aspx"
                           , new { id = @"\d+" }
                           , new[] { "GalleryThumbNailViewer" });

        routes.MapControls("gallery-image", "gallery/image/{id}.aspx"
                           , new { id = @"\d+" }
                           , new[] { "ViewPicture" });

        routes.MapControls("category", "{categoryType}/{slug}.aspx"
                           , new { categoryType = @"category|stories" }
                           , new[] { "CategoryEntryList" });

        routes.MapControls("tag", "tags/{tag}/default.aspx", null, new[] { "TagEntryList" });
        routes.MapControls("tag-cloud", "tags/default.aspx", null, new[] { "FullTagCloud" });
        routes.MapHttpHandler<RssTagHandler>("tag-rss", "tags/{tag}/rss.aspx");

        routes.MapHttpHandler<TrackBackHandler>("trackbacks", "services/trackbacks/{id}.aspx", new { id = @"\d+" });
        routes.MapXmlRpcHandler<PingBackService>("services/pingback/{id}.aspx", new { id = @"\d+" });
        routes.MapXmlRpcHandler<MetaWeblog>("metaweblogapi", "services/metablogapi.aspx", null);

        routes.Add("identicon", new Route("images/services/IdenticonHandler.ashx", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "identicon", action = "image" }) });
        routes.Add("captcha", new Route("images/services/CaptchaImage.ashx", new HttpRouteHandler<CaptchaImageHandler>(routes.ServiceLocator)));
        routes.Add("logout", new SubtextRoute("account/logout.ashx", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "account", action = "logout" }) });
    }
Example #21
0
 /// <summary>
 /// Method called by the application on startup.  
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Application_Start(object sender, EventArgs e)
 {
     var routes = new SubtextRouteMapper(RouteTable.Routes, Bootstrapper.ServiceLocator);
     StartApplication(routes, new HttpServerUtilityWrapper(Server));
     Application["DeprecatedPhysicalPaths"] = DeprecatedPhysicalPaths;
 }
 public static void Ignore(this SubtextRouteMapper routes, string url)
 {
     routes.Add(new IgnoreRoute(url));
 }
 public static void MapRoute(this SubtextRouteMapper routes, string routeName, string url, object defaults)
 {
     routes.MapRoute(routeName, url, defaults, null);
 }
 public static void MapImageRoute(this SubtextRouteMapper routes, string routeName, string url)
 {
     routes.Add(routeName, new ImageRoute(url));
 }
 public static void MapHttpHandler <THttpHandler>(this SubtextRouteMapper routes, string url, object constraints)
     where THttpHandler : IHttpHandler
 {
     routes.MapHttpHandler <THttpHandler>(null, url, constraints);
 }
Example #26
0
        public void RequestWithSubfolderForAggregatorBug_WithBlogHavingSubfolder_Matches()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/aggbug/123.aspx", "subfolder");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNotNull(routeData);
            Assert.AreEqual("Statistics", routeData.Values["controller"]);
            Assert.AreEqual("RecordAggregatorView", routeData.Values["action"]);
            Assert.AreEqual(routeData.RouteHandler.GetType(), typeof(MvcRouteHandler));
        }
 public static void MapHttpHandler <THttpHandler>(this SubtextRouteMapper routes, string url)
     where THttpHandler : IHttpHandler
 {
     routes.MapHttpHandler <THttpHandler>(null, url);
 }
Example #28
0
        public void RequestWithSubfolderForInstallDirectory_DoesNotMatch()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/install/default.aspx", "subfolder");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNull(routeData);
        }
 public static void MapControls(this SubtextRouteMapper routes, string url, object constraints,
                                IEnumerable <string> controls)
 {
     routes.MapControls(null, url, ToRouteValueDictionary(constraints), controls, null);
 }
Example #30
0
        public void RequestWithSubfolder_ForAdminDirectory_UsesDirectoryRouteHandler()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IDependencyResolver>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/admin/foo.aspx", "subfolder");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);
            var routeHandler = routeData.RouteHandler as DirectoryRouteHandler;

            //assert.
            Assert.IsNotNull(routeHandler);
            Assert.AreEqual("foo.aspx", routeData.Values["pathInfo"]);
        }
 public static void MapControls(this SubtextRouteMapper routes, string name, string url,
                                RouteValueDictionary constraints, IEnumerable <string> controls)
 {
     routes.MapControls(name, url, constraints, controls, null);
 }
Example #32
0
        public void RequestWithSubfolderForBlogRoot_WithAggregateEnabled_Matches()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/admin/foo.aspx", "subfolder");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);
            var routeHandler = routeData.RouteHandler as DirectoryRouteHandler;

            //assert.
            Assert.IsNotNull(routeHandler);
            Assert.AreEqual("foo.aspx", routeData.Values["pathInfo"]);
        }
Example #33
0
 /// <summary>
 /// Method called by the application on startup.  
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Application_Start(object sender, EventArgs e)
 {
     var routes = new SubtextRouteMapper(RouteTable.Routes, DependencyResolver.Current);
     StartApplication(routes, new HttpServerUtilityWrapper(Server));
     Application["DeprecatedPhysicalPaths"] = DeprecatedPhysicalPaths;
 }
Example #34
0
        public void RequestWithSubfolderForCommentApiController_WithBlogHavingSubfolder_Matches()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/comments/123.aspx", "subfolder");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert.
            Assert.IsNotNull(routeData);
            Assert.AreEqual("CommentApi", routeData.Values["controller"]);
            Assert.AreEqual("Create", routeData.Values["action"]);
            Assert.AreEqual(routeData.RouteHandler.GetType(), typeof(MvcRouteHandler));
        }
 public static void MapControls(this SubtextRouteMapper routes, string url, IEnumerable <string> controls)
 {
     routes.MapControls(url, null, controls);
 }
Example #36
0
        public void Request_ForDirectHttpHandlers_Matches(string url, string subfolder)
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest(url, subfolder);

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);

            //assert
            Assert.IsNotNull(routeData);
        }
 public static void MapHttpHandler <THttpHandler>(this SubtextRouteMapper routes, string name, string url)
     where THttpHandler : IHttpHandler
 {
     routes.Add(name, new SubtextRoute(url, new HttpRouteHandler <THttpHandler>(routes.ServiceLocator)));
 }
 public static void MapPageToControl(this SubtextRouteMapper routes, string controlName)
 {
     routes.MapControls(controlName, controlName + ".aspx", null, new[] { controlName });
 }
 public static void MapXmlRpcHandler <TXmlRpcHandler>(this SubtextRouteMapper routes, string name, string url,
                                                      object constraints)
     where TXmlRpcHandler : SubtextXmlRpcService
 {
     routes.Add(name, new SubtextRoute(url, new XmlRpcRouteHandler <TXmlRpcHandler>(routes.ServiceLocator)));
 }
Example #40
0
        public void RequestWithoutSubfolder_ForProvidersDirectory_UsesDirectoryRouteHandler()
        {
            //arrange
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().Object);
            Routes.RegisterRoutes(subtextRoutes);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/providers/foo.aspx");

            //act
            RouteData routeData = routes.GetRouteData(httpContext.Object);
            var routeHandler = routeData.RouteHandler as DirectoryRouteHandler;

            //assert.
            Assert.IsNotNull(routeHandler);
            Assert.AreEqual("foo.aspx", routeData.Values["pathInfo"]);
        }
 public static void MapSystemDirectory(this SubtextRouteMapper routes, string directoryName)
 {
     routes.Add(directoryName, new SystemDirectoryRoute(directoryName, routes.ServiceLocator));
 }