HttpApplicationTest.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » UnitTest » Web » 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 » Web Frameworks » Ingenious MVC 
Ingenious MVC » Ingenious » Mvc » UnitTest » Web » HttpApplicationTest.cs
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Ingenious.Mvc.Web.Forms;

namespace Ingenious.Mvc.UnitTest.Web{
  [TestFixture]
  public sealed class HttpApplicationTest : UnitTestBase
  {
    private CustomHttpApplication _httpApplication;
    private MockHttpBridge _httpBridge;

    protected override void SetUp()
    {
      base.SetUp();
       _httpApplication = new CustomHttpApplication(this);
      _httpBridge = new MockHttpBridge();
      HttpApplication.HttpBridge = _httpBridge;
    }

    [Test]
    [ExpectedException(typeof(IdException), "No root task ID was specified. Override or set the Ingenious.Mvc.Web.Forms.HttpApplication.RootTaskId property.")]
    public void TestSessionStartNoRootId()
    {
      _httpApplication.Session_Start(this, EventArgs.Empty);
    }

    [Test]
    public void TestSessionStart()
    {
      _httpApplication.SetRootTaskId("navigator");
      Assert.AreEqual(0, TaskManager.Tasks.Count);
      _httpApplication.Session_Start(this, EventArgs.Empty);
      Assert.IsTrue(_httpApplication.SessionStart);
      Assert.AreEqual(1, TaskManager.Tasks.Count);
    }

    #region Supporting Types

    private sealed class CustomHttpApplication : HttpApplication
    {
      private HttpApplicationTest _parent;
      private bool _sessionStart;
      private Id<INavigator> _rootTaskId;

      public bool SessionStart
      {
        get
        {
          return _sessionStart;
        }
      }

      protected override Id<INavigator> RootTaskId
      {
        get
        {
          return _rootTaskId;
        }
      }

      public CustomHttpApplication(HttpApplicationTest parent)
      {
        _parent = parent;
      }

      protected override TaskManager GetTaskManager()
      {
        return _parent.TaskManager;
      }

      protected override void Configure(TaskManager taskManager)
      {
        _parent.Configure("Valid");
      }

      protected override void OnSessionStart(object sender, EventArgs e)
      {
        base.OnSessionStart(sender, e);
        _sessionStart = true;
      }

      public void SetRootTaskId(Id<INavigator> rootTaskId)
      {
        _rootTaskId = rootTaskId;
      }
    }

    private sealed class MockHttpBridge : HttpApplication.IHttpBridge
    {
      private string _appRelativeCurrentExecutionFilePath = "~/Default.aspx";
      private string _rawUrl;
      private string _lastRedirect;

      public string AppRelativeCurrentExecutionFilePath
      {
        get
        {
          return _appRelativeCurrentExecutionFilePath;
        }
        set
        {
          _appRelativeCurrentExecutionFilePath = value;
        }
      }

      public string RawUrl
      {
        get
        {
          return _rawUrl;
        }
        set
        {
          _rawUrl = value;
        }
      }

      public string LastRedirect
      {
        get
        {
          return _lastRedirect;
        }
      }

      public void Redirect(string url)
      {
        _lastRedirect = url;
      }
    }

    #endregion
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.