RequestControllerTest.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » WebDashboard » MVC » 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 » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » WebDashboard » MVC » RequestControllerTest.cs
using System;
using NMock;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.WebDashboard.IO;
using ThoughtWorks.CruiseControl.WebDashboard.MVC;

namespace ThoughtWorks.CruiseControl.UnitTests.WebDashboard.MVC{
  [TestFixture]
  public class RequestControllerTest
  {
    private DynamicMock mockActionFactory;
    private DynamicMock mockRequest;
    private DynamicMock mockAction;
        private DynamicMock mockFingerprintFactory;
        private DynamicMock mockFingerprintableContentProvider;

    private RequestController controller;
    private IAction action;
    private IResponse response;
    private IRequest request;
      private IFingerprintFactory fingerprintFactory;
      private IConditionalGetFingerprintProvider fingerprintableContentProvider;

      [SetUp]
    public void Setup()
    {
      mockActionFactory = new DynamicMock(typeof(IActionFactory));
      mockRequest = new DynamicMock(typeof(IRequest));
      mockAction = new DynamicMock(typeof(IAction));
            mockFingerprintFactory = new DynamicMock(typeof(IFingerprintFactory));
          mockFingerprintableContentProvider = new DynamicMock(typeof (IConditionalGetFingerprintProvider));

      action = (IAction) mockAction.MockInstance;
      request = (IRequest) mockRequest.MockInstance;
            response = new HtmlFragmentResponse("<b>test</b>");
            fingerprintFactory = (IFingerprintFactory)mockFingerprintFactory.MockInstance;
          fingerprintableContentProvider =
              (IConditionalGetFingerprintProvider) mockFingerprintableContentProvider.MockInstance;

      controller = new RequestController((IActionFactory) mockActionFactory.MockInstance, request, fingerprintFactory);
    }

    private void VerifyAll()
    {
      mockActionFactory.Verify();
      mockAction.Verify();
      mockRequest.Verify();
            mockFingerprintFactory.Verify();
        mockFingerprintableContentProvider.Verify();
    }

    [Test]
    public void ShouldExecuteActionFromFactoryAndReturnHtml()
    {
      /// Setup
      mockActionFactory.ExpectAndReturn("Create", action, request);
      mockAction.ExpectAndReturn("Execute", response, request);
            mockFingerprintFactory.SetupResult("BuildFromRequest", ConditionalGetFingerprint.NOT_AVAILABLE, typeof(IRequest));

      /// Execute & Verify
      Assert.AreEqual(response, controller.Do());
      VerifyAll();
    }

        [Test]
        public void ShouldReturnNormalResponseWithNotAvailableFingerprintIfActionDoesNotHaveFingerPrintProvider()
        {
            mockActionFactory.ExpectAndReturn("CreateFingerprintProvider", null, request);
            mockActionFactory.ExpectAndReturn("Create", action, request);

            mockAction.ExpectAndReturn("Execute", response, request);

            IResponse actualResponse = controller.Do();

            Assert.IsAssignableFrom(typeof(HtmlFragmentResponse), actualResponse);
            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, actualResponse.ServerFingerprint);
        }

        [Test]
        public void ShouldReturnNormalResponseWithServerProvidedFingerprintIfClientDidNotProvideFingerprint()
        {
            mockActionFactory.ExpectAndReturn("CreateFingerprintProvider", fingerprintableContentProvider, request);
            mockFingerprintFactory.ExpectAndReturn("BuildFromRequest", ConditionalGetFingerprint.NOT_AVAILABLE, request);
            mockActionFactory.ExpectAndReturn("Create", action, request);

            mockAction.ExpectAndReturn("Execute", response, request);
            ConditionalGetFingerprint fingerprint = new ConditionalGetFingerprint(DateTime.Now, "test token");
            mockFingerprintableContentProvider.ExpectAndReturn("GetFingerprint", fingerprint, request);

            IResponse actualResponse = controller.Do();

            Assert.IsAssignableFrom(typeof(HtmlFragmentResponse), actualResponse);
            Assert.AreEqual(fingerprint, actualResponse.ServerFingerprint);
        }

      [Test]
      public void ShouldReturnNotModifiedResponseIfClientFingerprintMatchesServerFingerprint()
      {
            ConditionalGetFingerprint sharedFingerprint = new ConditionalGetFingerprint(new DateTime(1980, 10, 30), "None-Match-String");

            mockActionFactory.ExpectAndReturn("CreateFingerprintProvider", fingerprintableContentProvider, request);
            mockFingerprintFactory.ExpectAndReturn("BuildFromRequest", sharedFingerprint, request);
            mockActionFactory.ExpectAndReturn("Create", action, request);

            mockAction.ExpectAndReturn("Execute", response, request);
            mockFingerprintableContentProvider.ExpectAndReturn("GetFingerprint", sharedFingerprint, request);

            IResponse actualResponse = controller.Do();

            Assert.IsAssignableFrom(typeof(NotModifiedResponse), actualResponse);
            Assert.AreEqual(sharedFingerprint, actualResponse.ServerFingerprint);
      }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.