StatisticsControllerTests.cs :  » Bloggers » SubText » UnitTests » Subtext » SubtextWeb » Controllers » 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 » SubtextWeb » Controllers » StatisticsControllerTests.cs
using System;
using System.Collections.Specialized;
using System.Globalization;
using System.Web;
using MbUnit.Framework;
using Moq;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Services;
using Subtext.Infrastructure.ActionResults;
using Subtext.Web.Controllers;

namespace UnitTests.Subtext.SubtextWeb.Controllers{
    [TestFixture]
    public class StatisticsControllerTests
    {
        [Test]
        public void CtorSetsStatisticsService()
        {
            // arrange
            IStatisticsService service = new Mock<IStatisticsService>().Object;
            ISubtextContext subtextContext = new Mock<ISubtextContext>().Object;

            // act
            var controller = new StatisticsController(subtextContext, service);

            // assert
            Assert.AreSame(service, controller.StatisticsService);
        }

        [Test]
        public void TwoRequestsWithinTimeoutGetsNotModifiedResult()
        {
            // arrange
            IStatisticsService service = new Mock<IStatisticsService>().Object;
            var subtextContext = new Mock<ISubtextContext>();
            var headers = new NameValueCollection();
            headers.Add("If-Modified-Since", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));
            subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers);
            var controller = new StatisticsController(subtextContext.Object, service);

            // act
            var result = controller.RecordAggregatorView(123) as NotModifiedResult;

            // assert
            Assert.IsNotNull(result);
        }

        [Test]
        public void RequestForEntryRecordedAsAnAggregatorVisit()
        {
            // arrange
            EntryView entryView = null;
            var service = new Mock<IStatisticsService>();
            service.Setup(s => s.RecordAggregatorView(It.IsAny<EntryView>())).Callback<EntryView>(
                view => entryView = view);
            var headers = new NameValueCollection();
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog {Id = 99});
            subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers);
            var controller = new StatisticsController(subtextContext.Object, service.Object);

            // act
            controller.RecordAggregatorView(123);

            // assert
            Assert.IsNotNull(entryView);
            Assert.AreEqual(PageViewType.AggView, entryView.PageViewType);
            Assert.AreEqual(99, entryView.BlogId);
            Assert.AreEqual(123, entryView.EntryId);
        }

        [Test]
        public void RequestForInvalidEntryIdNotRecordedAsAnAggregatorVisit()
        {
            // arrange
            var service = new Mock<IStatisticsService>();
            service.Setup(s => s.RecordAggregatorView(It.IsAny<EntryView>())).Throws(
                new InvalidOperationException("RecordAggregatorView should not be called"));
            var headers = new NameValueCollection();
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog {Id = 99});
            subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers);
            var controller = new StatisticsController(subtextContext.Object, service.Object);

            // act, no assert
            controller.RecordAggregatorView(-1);
        }

        [Test]
        public void RequestReturnsFileResultContainingSinglePixelImage()
        {
            // arrange
            var service = new Mock<IStatisticsService>();
            var headers = new NameValueCollection();
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog {Id = 99});
            subtextContext.Setup(c => c.HttpContext.Request.Headers).Returns(headers);
            var controller = new StatisticsController(subtextContext.Object, service.Object);

            // act
            var result = controller.RecordAggregatorView(-1) as CacheableFileContentResult;

            // assert
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpCacheability.Public, result.Cacheability);
            Assert.AreEqual("image/gif", result.ContentType);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.