FormsViewManagerTest.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » UnitTest » Web » Forms » ViewManagers » 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 » Forms » ViewManagers » FormsViewManagerTest.cs
#region License

/**
 * Ingenious MVC : An MVC framework for .NET 2.0
 * Copyright (C) 2006, JDP Group
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Authors: - Kent Boogaart (kentcb@internode.on.net)
 */

#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Web;
using NUnit.Framework;
using Ingenious.Mvc;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.UnitTest.MockTypes;
using Ingenious.Mvc.ViewManagers;
using Ingenious.Mvc.Web.Forms.Views;
using Ingenious.Mvc.Web.Forms.ViewManagers;

namespace Ingenious.Mvc.UnitTest.Web.Forms.ViewManagers{
  /// <summary>
  /// Unit tests the <see cref="FormsViewManager"/> class.
  /// </summary>
  [TestFixture]
  public sealed class FormsViewManagerTest : UnitTestBase
  {
    private FormsViewManager _viewManager;
    private MockHttpBridge _httpBridge;

    protected override void SetUp()
    {
        base.SetUp();
      //this mocks out HTTP functionality for the web forms view manager
      _httpBridge = new MockHttpBridge(TaskManager);
      FormsViewManager.HttpBridge = _httpBridge;
      _httpBridge.AbandonSession();
        _viewManager = new FormsViewManager("vm", TaskManager);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestNullTask()
    {
      _viewManager.Activate(null, "v", null);
    }

    [Test]
    [ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IView was illegally provided for argument 'viewId'.")]
    public void TestViewIdEmpty()
    {
      _viewManager.Activate(CreateTask(), Id<IView>.Empty, null);
    }

    [Test]
    [ExpectedException(typeof(ViewManagerException), "No HTTP context was found via the HttpContext.Current property. The web forms view manager must be run in an ASP.NET environment.")]
    public void TestNoHttpContext()
    {
      //ensure the default HTTP bridge is used, which will require the HTTP context
      FormsViewManager.HttpBridge = null;
      Configure("Valid");
      TaskManager.StartTask("navigator");
    }

    [Test]
    public void TestSimple()
    {
      Configure("Valid");

      Task task = TaskManager.StartTask("navigator");
      INavigator navigator = TaskManager.GetNavigatorForTask(task);
      FormsViewManager viewManager = (FormsViewManager) TaskManager.GetViewManager("viewManager");

      MockPage view1 = (MockPage) viewManager.ActiveView;
      Assert.IsNotNull(view1);
      Assert.AreEqual("view1", view1.Id.ToString());

      /*
       * view1 ----> view2
       */
      navigator.NavigateTo("view2");
      MockPage view2 = (MockPage) viewManager.ActiveView;
      Assert.IsFalse(view1 == view2);
      Assert.IsNotNull(view2);
      Assert.AreEqual("view2", view2.Id.ToString());

      //kill the task and make sure that abandoned the session, since there was only one task running in the view manager
      Assert.IsFalse(_httpBridge.IsSessionEmpty);
      task.End();
      Assert.IsTrue(_httpBridge.IsSessionEmpty);

      //now start another task and make sure it was successful
      task = TaskManager.StartTask("navigator");
      Assert.AreEqual(view1.Id, viewManager.ActiveView.Id);
    }

    [Test]
    public void TestComplex()
    {
      Configure("Valid");

      Task task1 = TaskManager.StartTask("navigator");
      INavigator navigator1 = TaskManager.GetNavigatorForTask(task1);
      FormsViewManager viewManager = (FormsViewManager) TaskManager.GetViewManager("viewManager");

      MockPage view1 = (MockPage) viewManager.ActiveView;
      Assert.IsNotNull(view1);

      /*
       * view1 ----> view2
       */
      navigator1.NavigateTo("view2");
      MockPage view2 = (MockPage) viewManager.ActiveView;
      Assert.IsFalse(view1 == view2);
      Assert.IsNotNull(view2);
      Assert.AreEqual("view2", view2.Id.ToString());

      /*
       * view2 ----> view1
       */
      navigator1.NavigateTo("view1");
      Assert.AreEqual(view1.Id, viewManager.ActiveView.Id);

      /*
       * (new task) view3
       */
      Task task2 = TaskManager.StartTask("navigator2");
      INavigator navigator2 = TaskManager.GetNavigatorForTask(task2);
      MockPage view3 = (MockPage) viewManager.ActiveView;
      Assert.IsNotNull(view3);
      Assert.AreEqual("view3", view3.Id.ToString());

      /*
       * view3 --> view4
       */
      navigator2.NavigateTo("view4");
      MockPage view4 = (MockPage) viewManager.ActiveView;
      Assert.IsNotNull(view4);
      Assert.AreEqual("view4", view4.Id.ToString());

      /*
       * (implicitly end task2) view4 --> view2
       */
      navigator1.NavigateTo("view2");
      Assert.AreEqual(TaskState.Ended, task2.State);

      /*
       * (new task) view3
       */
      task2 = TaskManager.StartTask("navigator2");
      navigator2 = TaskManager.GetNavigatorForTask(task2);
      Assert.AreEqual(view3.Id, viewManager.ActiveView.Id);

      /*
       * (new task) view5
       */
      Task task3 = TaskManager.StartTask("navigator3");
      INavigator navigator3 = TaskManager.GetNavigatorForTask(task3);
      MockPage view5 = (MockPage) viewManager.ActiveView;
      Assert.IsNotNull(view5);
      Assert.AreEqual("view5", view5.Id.ToString());

      /*
       * view5 --> view7
       */
      navigator3.NavigateTo("view7");
      MockPage view7 = (MockPage) viewManager.ActiveView;
      Assert.IsNotNull(view7);
      Assert.AreEqual("view7", view7.Id.ToString());

      /*
       * (implicitly end tasks 3 and 2) view7 --> view2
       */
      navigator1.NavigateTo("view2");
      Assert.AreEqual(TaskState.Ended, task3.State);
      Assert.AreEqual(TaskState.Ended, task2.State);
    }

    [Test]
    public void TestBookmarking()
    {
      Configure("Valid");

      //simulate a user bookmarking a page that is not the first view in the navigation
      _httpBridge.IsNewSession = true;
      _httpBridge.PhysicalPath = "view2";

      Task task1 = TaskManager.StartTask("navigator");
      //no redirect is expected
      Assert.IsNull(_httpBridge.LastRedirect);
    }

    [Test]
    public void TestGraphNavigatorWorksAsRootNavigator()
    {
      Configure("GraphNavigator");

      //simulate a graph navigator as main navigator because a bug was found where doing so would result in an exception
      _httpBridge.IsNewSession = true;
      _httpBridge.PhysicalPath = "view1";

      TaskManager.StartTask("navigator");
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.