RequestExtensionsTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Util » 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 » Util » RequestExtensionsTests.cs
using System;
using System.Web;
using System.Web.Routing;
using MbUnit.Framework;
using Moq;
using Subtext.Framework.Util;

namespace UnitTests.Subtext.Framework.Util{
    [TestFixture]
    public class RequestExtensionsTests
    {
        [Test]
        public void GetDateFromRequest_WithDateValuesInRouteData_ReturnsCorrectDate()
        {
            // arrange
            var routeData = new RouteData();
            routeData.Values.Add("year", "2009");
            routeData.Values.Add("month", "01");
            routeData.Values.Add("day", "23");
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            DateTime theDate = requestContext.GetDateFromRequest();

            // assert
            Assert.AreEqual(new DateTime(2009, 01, 23), theDate);
        }

        [Test]
        public void GetDateFromRequest_WithNoDayValueInRouteValues_ReturnsFirstDayOfMonth()
        {
            // arrange
            var routeData = new RouteData();
            routeData.Values.Add("year", "2009");
            routeData.Values.Add("month", "01");

            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            DateTime theDate = requestContext.GetDateFromRequest();

            // assert
            Assert.AreEqual(new DateTime(2009, 01, 01), theDate);
        }

        [Test]
        public void GetSlugFromRequest_WithSlugInRouteData_ReturnsSlug()
        {
            // arrange
            var routeData = new RouteData();
            routeData.Values.Add("slug", "my-category");
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            string slug = requestContext.GetSlugFromRequest();

            // assert
            Assert.AreEqual("my-category", slug);
        }

        [Test]
        public void GetSlugFromRequest_WithoutSlugInRouteData_ReturnsNull()
        {
            // arrange
            var routeData = new RouteData();
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            string slug = requestContext.GetSlugFromRequest();

            // assert
            Assert.IsNull(slug);
        }

        [Test]
        public void GetIdFromRequest_WithIdInRouteData_ReturnsId()
        {
            // arrange
            var routeData = new RouteData();
            routeData.Values.Add("id", "123");
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            int? id = requestContext.GetIdFromRequest();

            // assert
            Assert.AreEqual(123, id);
        }

        [Test]
        public void GetIdFromRequest_WithoutIdInRouteData_ReturnsNull()
        {
            // arrange
            var routeData = new RouteData();
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            int? id = requestContext.GetIdFromRequest();

            // assert
            Assert.IsNull(id);
        }

        [Test]
        public void GetIdFromRequest_WithNonNumericIdInRouteData_ReturnsNull()
        {
            // arrange
            var routeData = new RouteData();
            routeData.Values.Add("id", "a1aoeu23");
            var requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);

            // act
            int? id = requestContext.GetIdFromRequest();

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