#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="OpenNavigator"/> class.
/// </summary>
public sealed class OpenNavigatorTest : UnitTestBase
{
private OpenNavigator _navigator;
private Id<INavigator> _id;
private Task _task;
protected override void SetUp()
{
_id = "n";
_task = CreateTask("t");
_navigator = new OpenNavigator(_id, _task, "sv", new MockViewManager(TaskManager));
}
[Test]
public void TestDefaultInstance()
{
Assert.IsNotNull(_navigator.ViewIds);
Assert.AreEqual(0, _navigator.ViewIds.Count);
}
[Test]
[ExpectedException(typeof(NavigationException), "No configuration has been supplied for the open navigator with ID 'n'.")]
public void TestNoConfiguration()
{
_navigator.NavigateTo("anywhere");
}
[Test]
public void TestCanNavigateTo()
{
Configure("NoViewsSpecified");
Task task = TaskManager.StartTask("navigator");
_navigator = (OpenNavigator) task.Manager.GetNavigatorForTask(task);
//any views valid if none specified
Assert.IsTrue(_navigator.CanNavigateTo("view1"));
Assert.IsTrue(_navigator.CanNavigateTo("view2"));
Assert.IsTrue(_navigator.CanNavigateTo("view3"));
//now specify a view and re-check
_navigator.ViewIds.Add("view3");
Assert.IsFalse(_navigator.CanNavigateTo("view1"));
Assert.IsFalse(_navigator.CanNavigateTo("view2"));
Assert.IsTrue(_navigator.CanNavigateTo("view3"));
}
[Test]
[ExpectedException(typeof(NavigationException), "According to the configuration for the navigator, it is not legal for the open navigator with ID 'navigator' to navigate to the view with ID 'view2'.")]
public void TestNavigateToInvalidView()
{
Configure("ViewsSpecified");
Task task = TaskManager.StartTask("navigator");
_navigator = (OpenNavigator) task.Manager.GetNavigatorForTask(task);
//view2 is not allowed
_navigator.NavigateTo("view2");
}
[Test]
public void TestNavigateToComplex()
{
Configure("ComplexConfiguration");
Task task = TaskManager.StartTask("navigator");
_navigator = (OpenNavigator) task.Manager.GetNavigatorForTask(task);
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
//view1 -> view4
_navigator.NavigateTo("view4");
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
//view4 -> view1
_navigator.NavigateTo("view1");
Assert.AreEqual("view1", _navigator.LastNavigateTo.ToString());
//view1 -> view8
_navigator.NavigateTo("view8");
Assert.AreEqual("view8", _navigator.LastNavigateTo.ToString());
//view8 -> view5
_navigator.NavigateTo("view5");
Assert.AreEqual("view5", _navigator.LastNavigateTo.ToString());
//view5 -> view4
_navigator.NavigateTo("view4");
Assert.AreEqual("view4", _navigator.LastNavigateTo.ToString());
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestSetCustomConfigurationNull()
{
((ICustomConfigurable) _navigator).SetCustomConfiguration(null);
}
[Test]
[ExpectedException(typeof(NavigatorException), "The OpenNavigator requires an instance of 'IdCollection`1' for its custom configuration but was given an instance of 'System.String'.")]
public void TestSetCustomConfigurationWrongType()
{
((ICustomConfigurable) _navigator).SetCustomConfiguration("test");
}
[Test]
public void TestSetCustomConfigurationValid()
{
IdCollection<Id<IView>> viewIds = new IdCollection<Id<IView>>();
viewIds.Add("V1");
viewIds.Add("V2");
Assert.AreEqual(0, _navigator.ViewIds.Count);
((ICustomConfigurable) _navigator).SetCustomConfiguration(viewIds);
Assert.AreEqual(2, _navigator.ViewIds.Count);
Assert.AreEqual(viewIds[0], _navigator.ViewIds[0]);
Assert.AreEqual(viewIds[1], _navigator.ViewIds[1]);
}
}
}
|