BlogRequestTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Web » HttpModules » 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 » Web » HttpModules » BlogRequestTests.cs
using System;
using System.Collections.Specialized;
using System.Web;
using MbUnit.Framework;
using Moq;
using Subtext.Framework.Web.HttpModules;

namespace UnitTests.Subtext.Framework.Web.HttpModules{
    [TestFixture]
    public class BlogRequestTests
    {
        [Test]
        public void Ctor_WithRequestWithSubfolder_CreatesBlogRequestWithSubfolder()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/foo/bar", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual("foo", blogRequest.Subfolder);
        }

        [Test]
        public void Ctor_WithHostHavingPort_StripsPort()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com:1234", "/", "/foo/bar", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual("example.com", blogRequest.Host);
        }

        [Test]
        public void Ctor_WithRequestHavingNoHostInParameters_CreatesBlogRequestWithHostAuthority()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/foo/bar", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual("example.com", blogRequest.Host);
        }

        [Test]
        public void Ctor_WithRequestForLoginPage_SetsRequestLocationToLogin()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/login.aspx", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual(RequestLocation.LoginPage, blogRequest.RequestLocation);
        }

        [Test]
        public void Ctor_WithRequestForSystemMessage_SetsRequestLocationToSystemMessages()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/SystemMessages/anything.aspx", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual(RequestLocation.SystemMessages, blogRequest.RequestLocation);
        }

        [Test]
        public void Ctor_WithRequestForHostAdmin_SetsRequestLocationToHostAdmin()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/HostAdmin/anything.aspx", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual(RequestLocation.HostAdmin, blogRequest.RequestLocation);
        }

        [Test]
        public void Ctor_WithRequestForInstallDirectoryRoot_SetsRequestLocationToInstallDirectory()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/Install", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual(RequestLocation.Installation, blogRequest.RequestLocation);
        }

        [Test]
        public void Ctor_WithRequestForInstallDirectory_SetsRequestLocationToInstallDirectory()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/Install/anything.aspx", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual(RequestLocation.Installation, blogRequest.RequestLocation);
        }

        [Test]
        public void Ctor_WithRequestForStaticFile_SetsRequestLocationToStaticFile()
        {
            //arrange
            Mock<HttpRequestBase> request = CreateRequest("example.com", "/", "/Install/anything.css", true);

            //act
            var blogRequest = new BlogRequest(request.Object);

            //assert
            Assert.AreEqual(RequestLocation.StaticFile, blogRequest.RequestLocation);
        }

        [Test]
        public void Ctor_WithRequestForBlog_SetsBlogNotRequiredFalse()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false, RequestLocation.Blog,
                                              "/");

            //assert
            Assert.IsFalse(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForHostAdmin_SetsBlogNotRequiredTrue()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false,
                                              RequestLocation.HostAdmin, "/");

            //assert
            Assert.IsTrue(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForUpgrade_SetsBlogNotRequiredTrue()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false, RequestLocation.Upgrade,
                                              "/");

            //assert
            Assert.IsTrue(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForSkins_SetsBlogNotRequiredTrue()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false, RequestLocation.Skins,
                                              "/");

            //assert
            Assert.IsTrue(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForStaticFile_SetsBlogNotRequiredTrue()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false,
                                              RequestLocation.StaticFile, "/");

            //assert
            Assert.IsTrue(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForSystemMessages_SetsBlogNotRequiredTrue()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false,
                                              RequestLocation.SystemMessages, "/");

            //assert
            Assert.IsTrue(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForLoginPage_SetsBlogNotRequiredFalse()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false,
                                              RequestLocation.LoginPage, "/");

            //assert
            Assert.IsFalse(blogRequest.BlogNotRequired);
        }

        [Test]
        public void Ctor_WithRequestForInstallation_SetsBlogNotRequiredTrue()
        {
            //arrange, act
            var blogRequest = new BlogRequest(null, null, new Uri("http://example.com"), false,
                                              RequestLocation.Installation, "/");

            //assert
            Assert.IsTrue(blogRequest.BlogNotRequired);
        }

        private static Mock<HttpRequestBase> CreateRequest(string host, string applicationPath, string rawUrl,
                                                           bool useParametersForHost)
        {
            var request = new Mock<HttpRequestBase>();
            request.Setup(r => r.RawUrl).Returns(rawUrl);
            request.Setup(r => r.Path).Returns(rawUrl);
            request.Setup(r => r.FilePath).Returns(rawUrl);
            request.Setup(r => r.ApplicationPath).Returns(applicationPath);
            request.Setup(r => r.IsLocal).Returns(host == "localhost");
            request.Setup(r => r.Url).Returns(new Uri("http://" + host + rawUrl));

            var parameters = new NameValueCollection();
            parameters["HTTP_HOST"] = useParametersForHost ? host : null;
            request.Setup(r => r.Params).Returns(parameters);
            return request;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.