#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="WizardNavigator"/> class.
/// </summary>
public sealed class WizardNavigatorTest : UnitTestBase
{
private WizardNavigator _navigator;
private Id<INavigator> _id;
private Task _task;
protected override void SetUp()
{
_id = "n";
_task = CreateTask("t");
_navigator = new WizardNavigator(_id, _task, "sv", new MockViewManager(TaskManager));
}
[Test]
public void TestConstructor()
{
Assert.IsNotNull(_navigator.ViewIds);
Assert.AreEqual(0, _navigator.ViewIds.Count);
}
[Test]
public void TestAddViews()
{
_navigator.ViewIds.Add("Welcome");
_navigator.ViewIds.Add("EnterDetails");
_navigator.ViewIds.Add("Summary");
Assert.AreEqual(3, _navigator.ViewIds.Count);
}
[Test]
[ExpectedException(typeof(NavigatorException), "The from view with ID 'fromView' could not be found in the view IDs added to the wizard navigator with ID 'n'. Unable to add an alias for a view that has not been added to the WizardNavigator.ViewIds collection.")]
public void TestAddAliasForNonExistantFromView()
{
_navigator.ViewIds.Add("toView");
_navigator.AddAlias("fromView", "toView", "myAlias");
}
[Test]
[ExpectedException(typeof(NavigatorException), "The to view with ID 'toView' could not be found in the view IDs added to the wizard navigator with ID 'n'. Unable to add an alias for a view that has not been added to the WizardNavigator.ViewIds collection.")]
public void TestAddAliasForNonExistantToView()
{
_navigator.ViewIds.Add("fromView");
_navigator.AddAlias("fromView", "toView", "myAlias");
}
[Test]
public void TestAddAliasValid()
{
_navigator.ViewIds.Add("fromView");
_navigator.ViewIds.Add("toView");
_navigator.AddAlias("fromView", "toView", "myAlias");
Assert.AreEqual("toView", _navigator.GetViewForAlias("fromView", "myAlias").ToString());
}
[Test]
public void TestSimple()
{
Configure("SimpleConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
//the framework should have navigated to the starting view
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
}
[Test]
[ExpectedException(typeof(NavigationException), "The WizardNavigator with ID 'navigator' was asked to navigate to the previous view. However, the current view with ID 'view1' has no previous view.")]
public void TestPreviousInvalid()
{
Configure("MediumConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
_navigator.NavigateToPrevious();
}
[Test]
[ExpectedException(typeof(NavigationException), "The WizardNavigator with ID 'navigator' was asked to navigate to the next view. However, the current view with ID 'view4' has no next view.")]
public void TestNextInvalid()
{
Configure("MediumConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
_navigator.NavigateToNext();
_navigator.NavigateToNext();
_navigator.NavigateToNext();
_navigator.NavigateToNext();
}
[Test]
public void TestNextAndPreviousValid()
{
Configure("MediumConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
//try out next
_navigator.NavigateToNext();
Assert.AreEqual("view2", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToNext();
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToNext();
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
//try out previous
_navigator.NavigateToPrevious();
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view2", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
}
[Test]
public void TestConfigModifiedAtRuntime()
{
Configure("ComplexConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
_navigator.NavigateToNext();
_navigator.NavigateToNext();
_navigator.NavigateToNext();
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
_navigator.NavigateToPrevious();
_navigator.NavigateToPrevious();
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
//remove view3 and try again
_navigator.ViewIds.Remove("view3");
_navigator.NavigateToNext();
_navigator.NavigateToNext();
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
_navigator.NavigateToPrevious();
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
//add back view3 and try again
_navigator.ViewIds.Add("view3");
_navigator.NavigateToNext();
_navigator.NavigateToNext();
_navigator.NavigateToNext();
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
_navigator.NavigateToPrevious();
_navigator.NavigateToPrevious();
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
}
[Test]
public void TestComplex()
{
Configure("ComplexConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
_navigator.NavigateTo((Id<IView>) "skipView2");
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToNext();
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
_navigator.NavigateTo((Id<IView>) "skipToStart");
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
_navigator.NavigateTo((Id<IView>) "skipToEnd");
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view2", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
//now do the same as above but with view IDs instead of alias IDs
_navigator.NavigateTo("view3");
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToNext();
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
_navigator.NavigateTo("view1");
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
_navigator.NavigateTo("view4");
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view3", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view2", _navigator.LastNavigateTo.ToString());
_navigator.NavigateToPrevious();
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
}
[Test]
[ExpectedException(typeof(NavigatorException), "The to view with ID 'view2' could not be found in the view IDs added to the wizard navigator with ID 'navigator'. Unable to add an alias for a view that has not been added to the WizardNavigator.ViewIds collection.")]
public void TestInvalidAlias()
{
Configure("InvalidAlias");
Task task = TaskManager.StartTask("navigator");
_navigator = (WizardNavigator) task.Manager.GetNavigatorForTask(task);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestSetCustomConfigurationNull()
{
((ICustomConfigurable) _navigator).SetCustomConfiguration(null);
}
[Test]
[ExpectedException(typeof(NavigatorException), "The WizardNavigator requires an instance of 'Ingenious.Mvc.Navigators.WizardNavigator+CustomConfiguration' for its custom configuration but was given an instance of 'System.String'.")]
public void TestSetCustomConfigurationWrongType()
{
((ICustomConfigurable) _navigator).SetCustomConfiguration("test");
}
[Test]
public void TestSetCustomConfigurationValid()
{
Id<IView> v1 = "V1";
Id<IView> v2 = "V2";
Id<IView> v3 = "V3";
Id<IView> v4 = "V4";
Id<IView> va1 = "VA1";
Id<IView> va2 = "VA2";
Id<IView> va3 = "VA3";
WizardNavigator.CustomConfiguration customConfiguration = new Ingenious.Mvc.Navigators.WizardNavigator.CustomConfiguration();
customConfiguration.ViewIds.Add(v1);
customConfiguration.ViewIds.Add(v2);
customConfiguration.ViewIds.Add(v3);
customConfiguration.ViewIds.Add(v4);
customConfiguration.Aliases.Add(new GraphNavigator.AliasInfo(v1, v3, "myAlias"));
((ICustomConfigurable) _navigator).SetCustomConfiguration(customConfiguration);
Assert.AreEqual(4, _navigator.ViewIds.Count);
Assert.AreEqual(v1, _navigator.ViewIds[0]);
Assert.AreEqual(v2, _navigator.ViewIds[1]);
Assert.AreEqual(v3, _navigator.ViewIds[2]);
Assert.AreEqual(v4, _navigator.ViewIds[3]);
Assert.AreEqual(v3, _navigator.GetViewForAlias(v1, "myAlias"));
}
}
}
|