PageRouteTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Routing » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » UnitTests » Subtext » Framework » Routing » PageRouteTests.cs
using System;
using System.Web;
using System.Web.Routing;
using MbUnit.Framework;
using Moq;
using Ninject;
using Subtext.Framework.Routing;
using Subtext.Framework.Web.HttpModules;
using Subtext.Infrastructure;

namespace UnitTests.Subtext.Framework.Routing{
    [TestFixture]
    public class PageRouteTests
    {
        [Test]
        public void GetVirtualPath_WithoutSubolder_ReturnsUrlWithoutSubfolder()
        {
            //arrange
            var route = new PageRoute("archive/{slug}.aspx", "~/aspx/Dtp.aspx", null,
                                      new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/slug.aspx");
            var routeData = new RouteData();
            var requestContext = new RequestContext(httpContext.Object, routeData);

            //act
            VirtualPathData virtualPath = route.GetVirtualPath(requestContext,
                                                               new RouteValueDictionary(new {slug = "test-slug"}));

            //assert
            Assert.IsNotNull(virtualPath);
            Assert.AreEqual("archive/test-slug.aspx", virtualPath.VirtualPath);
        }

        [Test]
        public void GetVirtualPath_WithSubolder_ReturnsUrlWithSubfolder()
        {
            //arrange
            var route = new PageRoute("archive/{slug}.aspx", "~/aspx/Dtp.aspx", null,
                                      new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/slug.aspx");
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "subfolder");
            var requestContext = new RequestContext(httpContext.Object, routeData);

            //act
            VirtualPathData virtualPath = route.GetVirtualPath(requestContext,
                                                               new RouteValueDictionary(new {slug = "test-slug"}));

            //assert
            Assert.IsNotNull(virtualPath);
            Assert.AreEqual("subfolder/archive/test-slug.aspx", virtualPath.VirtualPath);
        }

        [Test]
        public void Request_ForPageRouteWithConstraints_MatchesWhenConstraintsAreSatisfied()
        {
            //arrange
            var route = new PageRoute("archive/{year}/{month}/{day}/{slug}.aspx", "~/aspx/Dtp.aspx", null,
                                      new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object)
            {Constraints = new RouteValueDictionary(new {year = @"\d{4}"})};
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/2008/01/23/slug.aspx");
            var blogRequest = new BlogRequest("localhost", null, new Uri("http://localhost"), false);

            //act
            RouteData routeData = route.GetRouteData(httpContext.Object, blogRequest);

            //assert
            Assert.IsNotNull(routeData);
        }

        [Test]
        public void RequestWithSubfolder_ForBlogPostWithSubfolder_Matches()
        {
            //arrange
            var subtextRoute = new PageRoute("archive/{slug}", "~/aspx/Dtp.aspx", null,
                                             new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/blogsubfolder/archive/blog-post");
            //This info is provided by the BlogRequestModule.
            var blogRequest = new BlogRequest("localhost", "blogsubfolder",
                                              new Uri("http://localhost/blogsubfolder/archive/blog-post"), true);

            //act
            RouteData routeData = subtextRoute.GetRouteData(httpContext.Object, blogRequest);

            //assert.
            Assert.IsNotNull(routeData);
            Assert.AreEqual("blog-post", routeData.Values["slug"]);
            Assert.AreEqual("blogsubfolder", routeData.Values["subfolder"]);
        }

        [Test]
        public void RequestWithoutSubfolder_ForBlogPostWithSubfolder_DoesNotMatch()
        {
            //arrange
            var subtextRoute = new PageRoute("archive/{slug}", "~/aspx/Dtp.aspx", null,
                                             new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/blog-post");
            //This info is provided by the BlogRequestModule.
            var blogRequest = new BlogRequest("localhost", "subfolder", new Uri("http://localhost/archive/blog-post"),
                                              true);

            //act
            RouteData routeData = subtextRoute.GetRouteData(httpContext.Object, blogRequest);

            //assert.
            Assert.IsNull(routeData);
        }

        [Test]
        public void RequestWithoutSubfolder_ForBlogPostWithoutSubfolder_Matches()
        {
            //arrange
            var subtextRoute = new PageRoute("archive/{slug}", "~/aspx/Dtp.aspx", null,
                                             new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/archive/blog-post");
            //This info is provided by the BlogRequestModule.
            var blogRequest = new BlogRequest("localhost", string.Empty, new Uri("http://localhost/archive/blog-post"),
                                              true);

            //act
            RouteData routeData = subtextRoute.GetRouteData(httpContext.Object, blogRequest);

            //assert.
            Assert.IsNotNull(routeData);
            Assert.AreEqual("blog-post", routeData.Values["slug"]);
            Assert.AreEqual(string.Empty, routeData.Values["subfolder"]);
        }

        [Test]
        public void RequestWithSubfolder_ForBlogPostWithoutSubfolder_DoesNotMatch()
        {
            //arrange
            var subtextRoute = new PageRoute("archive/{slug}", "~/aspx/Dtp.aspx", null,
                                             new Mock<ISubtextPageBuilder>().Object, new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/archive/blog-post");
            //This info is provided by the BlogRequestModule.
            var blogRequest = new BlogRequest("localhost", string.Empty,
                                              new Uri("http://localhost/subfolder/archive/blog-post"), true);

            //act
            RouteData routeData = subtextRoute.GetRouteData(httpContext.Object, blogRequest);

            //assert.
            Assert.IsNull(routeData);
        }

        [Test]
        public void GetRouteData_MatchingTheImplicitSubfolderRoute_ReturnsParentDirectoryRoute()
        {
            //arrange
            var route = new PageRoute("url", "~/aspx/Dtp.aspx", new[] {"foo"}, new Mock<ISubtextPageBuilder>().Object,
                                      new Mock<IServiceLocator>().Object);
            var httpContext = new Mock<HttpContextBase>();
            httpContext.FakeRequest("~/subfolder/url");
            var blogRequest = new BlogRequest("localhost", "subfolder", new Uri("http://localhost"), false);

            //act
            RouteData routeData = route.GetRouteData(httpContext.Object, blogRequest);

            //assert
            Assert.AreEqual(route, routeData.Route);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.