NavigatorBaseTest.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » UnitTest » Navigators » 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 » Navigators » NavigatorBaseTest.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 NUnit.Framework;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.Factories;
using Ingenious.Mvc.Navigators;
using Ingenious.Mvc.UnitTest.MockTypes;

namespace Ingenious.Mvc.UnitTest.Navigators{
  /// <summary>
  /// Unit tests the <see cref="NavigatorBase"/> class.
  /// </summary>
  public sealed class NavigatorBaseTest : UnitTestBase
  {
    private ConcreteNavigator _navigator;
    private Id<INavigator> _id;
    private Task _task;

    private static readonly Id<IView> _illegalView = "illegalView";

    protected override void SetUp()
    {
      _id = "n";
      _task = CreateTask("t");
      _navigator = new ConcreteNavigator(_id, _task, "sv", new MockViewManager(TaskManager));
    }

    [Test]
    [ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.INavigator was illegally provided for argument 'id'.")]
    public void TestConstructorIdEmpty()
    {
      _navigator = new ConcreteNavigator(Id<INavigator>.Empty, null, "v", null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestConstructorTaskNull()
    {
      _navigator = new ConcreteNavigator(_id, null, "v", null);
    }

    [Test]
    [ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IView was illegally provided for argument 'startingViewId'.")]
    public void TestConstructorStartingViewIdEmpty()
    {
      _navigator = new ConcreteNavigator(_id, _task, Id<IView>.Empty, null);
    }

    [Test]
    [ExpectedException(typeof(ArgumentNullException))]
    public void TestConstructorViewManagerNull()
    {
      _navigator = new ConcreteNavigator(_id, _task, "sv", null);
    }

    [Test]
    public void TestConstructor()
    {
      IViewManager viewManager = new MockViewManager(TaskManager);
      _navigator = new ConcreteNavigator(_id, _task, "sv", viewManager);

      Assert.AreEqual(_id, _navigator.Id);
      Assert.AreEqual("t", _navigator.Task.Id.ToString());
      Assert.AreEqual("sv", _navigator.StartingViewId.ToString());
      Assert.AreSame(viewManager, _navigator.ViewManager);
    }

    [Test]
    [ExpectedException(typeof(NavigationException), "No configuration has been supplied via the TaskManager.Configuration property.")]
    public void TestNavigateToConfigurationNull()
    {
      _navigator.NavigateTo("anywhere");
    }

    [Test]
    [ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IView was illegally provided for argument 'viewId'.")]
    public void TestNavigateToViewIdEmpty()
    {
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      _navigator.NavigateTo(Id<IView>.Empty);
    }

    [Test]
    [ExpectedException(typeof(NavigationException), "The navigator with ID 'n' was unable to find the view with ID 'v'.")]
    public void TestNavigateToViewNotFound()
    {
      TaskManager.ConfigurationInfo = new ConfigurationInfo();
      _navigator.NavigateTo("v");
    }

    [Test]
    public void TestNavigateValid()
    {
      Configure("TestNavigateValid");

      Task task = TaskManager.StartTask("navigator");
      _navigator = (ConcreteNavigator) task.Manager.GetNavigatorForTask(task);

      //the framework should have navigated to the starting view
      Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
      //now we'll navigate to the second view
      _navigator.NavigateTo("view2");
      Assert.AreEqual("view2", _navigator.LastNavigateTo.ToString());
    }

    [Test]
    [ExpectedException(typeof(NavigationException), "That view is illegal.")]
    public void TestNavigateIllegal()
    {
      Configure("TestNavigateIllegal");

      Task task = TaskManager.StartTask("navigator");
      _navigator = (ConcreteNavigator) task.Manager.GetNavigatorForTask(task);

      //the framework should have navigated to the starting view
      Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
      //now we'll try and navigate to the illegal view
      _navigator.NavigateTo("illegalView");
    }

    #region Supporting Types

    private sealed class ConcreteNavigator : NavigatorBase
    {
      public new IViewManager ViewManager
      {
        get
        {
          return base.ViewManager;
        }
      }

      public ConcreteNavigator(Id<INavigator> id, Task task, Id<IView> startingViewId, IViewManager viewManager) : base(id, task, startingViewId, viewManager)
      {
      }

      protected override bool AssertNavigateToValid(ref Id<IView> viewId, bool throwOnError)
      {
        if (viewId == _illegalView)
        {
          if (throwOnError)
          {
            throw new NavigationException("That view is illegal.", ViewManager.ActiveView, viewId);
          }
          else
          {
            return false;
          }
        }
        else
        {
          return true;
        }
      }
    }

    #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.