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