AdminUrlHelperTests.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 » AdminUrlHelperTests.cs
using System.Web;
using System.Web.Routing;
using MbUnit.Framework;
using Moq;
using Ninject;
using Subtext.Framework.Components;
using Subtext.Framework.Routing;
using Subtext.Infrastructure;

namespace UnitTests.Subtext.Framework.Routing{
    [TestFixture]
    public class AdminUrlHelperTests
    {
        [Test]
        public void PostsList_WithBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.PostsList();

            //assert
            Assert.AreEqual("/sub/admin/posts/default.aspx", url);
        }

        [Test]
        public void PostsEdit_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.PostsEdit();

            //assert
            Assert.AreEqual("/sub/admin/posts/edit.aspx", url);
        }

        [Test]
        public void ArticlesList_WithBlogHavingSubfolder_RendersUrlToArticlesListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.ArticlesList();

            //assert
            Assert.AreEqual("/sub/admin/articles/default.aspx", url);
        }

        [Test]
        public void ArticlesEdit_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToArticlesListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.ArticlesEdit();

            //assert
            Assert.AreEqual("/sub/admin/articles/edit.aspx", url);
        }

        [Test]
        public void FeedbackList_WithBlogHavingSubfolder_RendersUrlToFeedbackListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.FeedbackList();

            //assert
            Assert.AreEqual("/sub/admin/feedback/default.aspx", url);
        }

        [Test]
        public void FeedbackEdit_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToFeedbackListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.FeedbackEdit(123);

            //assert
            Assert.AreEqual("/sub/admin/feedback/edit.aspx?return-to-post=true&FeedbackID=123", url);
        }

        [Test]
        public void LinksEdit_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.LinksEdit();

            //assert
            Assert.AreEqual("/sub/admin/EditLinks.aspx", url);
        }

        [Test]
        public void GalleriesEdit_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.GalleriesEdit();

            //assert
            Assert.AreEqual("/sub/admin/EditGalleries.aspx", url);
        }

        [Test]
        public void EditCategories_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.EditCategories(CategoryType.PostCollection);

            //assert
            Assert.AreEqual("/sub/admin/EditCategories.aspx?catType=PostCollection", url);
        }

        [Test]
        public void ErrorLog_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.ErrorLog();

            //assert
            Assert.AreEqual("/sub/admin/ErrorLog.aspx", url);
        }

        [Test]
        public void Home_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.Home();

            //assert
            Assert.AreEqual("/sub/admin/default.aspx", url);
        }

        [Test]
        public void ImportExport_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.ImportExport();

            //assert
            Assert.AreEqual("/sub/admin/ImportExport.aspx", url);
        }

        [Test]
        public void ExportUrl_WithEmbedFalseAndSubFolder_RendersUrlWithQueryStringParameter()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.Export(false);

            //assert
            Assert.AreEqual("/sub/admin/export.ashx?embed=False", url);
        }

        [Test]
        public void ExportUrl_WithEmbedTrue_RendersUrlWithQueryStringParameter()
        {
            //arrange
            AdminUrlHelper helper = SetupUrlHelper("/");

            //act
            string url = helper.Export(true);

            //assert
            Assert.AreEqual("/admin/export.ashx?embed=True", url);
        }

        [Test]
        public void Statistics_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.Statistics();

            //assert
            Assert.AreEqual("/sub/admin/Statistics.aspx", url);
        }

        [Test]
        public void Options_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.Options();

            //assert
            Assert.AreEqual("/sub/admin/Options.aspx", url);
        }

        [Test]
        public void Credits_WithCategoryTypeAndBlogHavingSubfolder_RendersUrlToPostsListPage()
        {
            //arrange
            var routeData = new RouteData();
            routeData.Values.Add("subfolder", "sub");
            AdminUrlHelper helper = SetupUrlHelper("/", routeData);

            //act
            string url = helper.Credits();

            //assert
            Assert.AreEqual("/sub/admin/Credits.aspx", url);
        }

        private static AdminUrlHelper SetupUrlHelper(string appPath)
        {
            return SetupUrlHelper(appPath, new RouteData());
        }

        private static AdminUrlHelper SetupUrlHelper(string appPath, RouteData routeData)
        {
            var routes = new RouteCollection();
            var subtextRoutes = new SubtextRouteMapper(routes, new Mock<IServiceLocator>().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 UrlHelper(requestContext, routes);
            return new AdminUrlHelper(helper);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.