#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;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.UnitTest.MockTypes;
using Ingenious.Mvc.Navigators;
using Ingenious.Mvc.ViewManagers;
using Ingenious.Mvc.Windows.Forms.ViewManagers;
using Ingenious.Mvc.Windows.Forms.Views;
namespace Ingenious.Mvc.UnitTest.Windows.Forms.ViewManagers{
/// <summary>
/// Unit tests the <see cref="WizardViewManager"/> class.
/// </summary>
public sealed class WizardViewManagerTest : UnitTestBase
{
private WizardViewManager _viewManager;
protected override void SetUp()
{
_viewManager = new WizardViewManager("vm", TaskManager);
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The wizard view manager with ID 'viewManager' does not have a container view ID specified for it. You must specify the ID of the view to be used as a container for the wizard via the WizardViewManager.ContainerViewId property.")]
public void TestNoContainerView()
{
Configure("ValidSimple");
//clear the custom config, thus clearing the container view info
TaskManager.ConfigurationInfo.NavigatorInfos["navigator"].ViewManagerInfo.CustomConfiguration = new WizardViewManager.CustomConfiguration();
TaskManager.StartTask("navigator");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The wizard view manager with ID 'viewManager' has container view with ID 'view' specified for it. However, this view is of type 'Ingenious.Mvc.UnitTest.MockTypes.MockView' and does not implement the required interface 'Ingenious.Mvc.Windows.Forms.Views.IFormView'.")]
public void TestDoesntImplementIFormView()
{
Configure("DoesntImplementIFormView");
TaskManager.StartTask("navigator");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The wizard view manager with ID 'viewManager' has container view with ID 'view' specified for it. However, this view is of type 'Ingenious.Mvc.UnitTest.Windows.Forms.ViewManagers.WizardViewManagerTest+MockForm' and does not implement the required interface 'Ingenious.Mvc.Windows.Forms.Views.IUserControlContainer'.")]
public void TestDoesntImplementIUserControlContainer()
{
Configure("DoesntImplementIUserControlContainer");
TaskManager.StartTask("navigator");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The view with ID 'view1' has type 'Ingenious.Mvc.UnitTest.MockTypes.MockView' as its type, but that type does not implement the required interface 'Ingenious.Mvc.Windows.Forms.Views.IUserControlView'.")]
public void TestDoesntImplementIUserControlView()
{
Configure("DoesntImplementIUserControlView");
TaskManager.StartTask("navigator");
}
[Test]
public void TestValidSimple()
{
Configure("ValidSimple");
Task task = TaskManager.StartTask("navigator");
INavigator navigator = TaskManager.GetNavigatorForTask(task);
WizardViewManager viewManager = (WizardViewManager) TaskManager.GetViewManagerForTask(task);
Assert.IsNotNull(viewManager.ActiveView);
Assert.IsTrue((viewManager.GetContainerFormForTask(task) as MockFormView).WasModal);
Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
}
[Test]
public void TestValidComplex()
{
Configure("ValidComplex");
Task task = TaskManager.StartTask("navigator");
WizardNavigator navigator = (WizardNavigator) TaskManager.GetNavigatorForTask(task);
WizardViewManager viewManager = (WizardViewManager) TaskManager.GetViewManagerForTask(task);
Assert.IsNotNull(viewManager.ActiveView);
Assert.IsTrue((viewManager.GetContainerFormForTask(task) as MockFormView).WasModal);
Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
//go to view2
navigator.NavigateToNext();
Assert.IsNotNull(viewManager.ActiveView);
Assert.AreEqual("view2", viewManager.ActiveView.Id.ToString());
//back to view1
navigator.NavigateToPrevious();
Assert.IsNotNull(viewManager.ActiveView);
Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
//through to view5
navigator.NavigateToNext();
navigator.NavigateToNext();
navigator.NavigateToNext();
navigator.NavigateToNext();
Assert.IsNotNull(viewManager.ActiveView);
Assert.AreEqual("view5", viewManager.ActiveView.Id.ToString());
//back to view1 again
navigator.NavigateToPrevious();
navigator.NavigateToPrevious();
navigator.NavigateToPrevious();
navigator.NavigateToPrevious();
Assert.IsNotNull(viewManager.ActiveView);
Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
}
[Test]
public void TestValidNonModal()
{
Configure("ValidNonModal");
Task task = TaskManager.StartTask("navigator");
INavigator navigator = TaskManager.GetNavigatorForTask(task);
WizardViewManager viewManager = (WizardViewManager) TaskManager.GetViewManagerForTask(task);
Assert.IsNotNull(viewManager.ActiveView);
Assert.IsFalse((viewManager.GetContainerFormForTask(task) as MockFormView).WasModal);
Assert.AreEqual("view1", viewManager.ActiveView.Id.ToString());
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestSetCustomConfigurationNull()
{
((ICustomConfigurable) _viewManager).SetCustomConfiguration(null);
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The WizardViewManager requires an instance of 'Ingenious.Mvc.Windows.Forms.ViewManagers.WizardViewManager+CustomConfiguration' for its custom configuration but was given an instance of 'System.String'.")]
public void TestSetCustomConfigurationWrongType()
{
((ICustomConfigurable) _viewManager).SetCustomConfiguration("test");
}
[Test]
public void TestSetCustomConfigurationValid()
{
Ingenious.Mvc.Windows.Forms.ViewManagers.WizardViewManager.CustomConfiguration customConfig = new Ingenious.Mvc.Windows.Forms.ViewManagers.WizardViewManager.CustomConfiguration();
customConfig.ContainerName = "containerName";
customConfig.ContainerViewId = "containerViewId";
((ICustomConfigurable) _viewManager).SetCustomConfiguration(customConfig);
Assert.AreEqual("containerName", _viewManager.ContainerName);
Assert.AreEqual("containerViewId", _viewManager.ContainerViewId.ToString());
}
#region Supporting Types
private sealed class MockForm : IFormView
{
public bool LeaveOpen
{
get
{
return false;
}
}
public bool IsModal
{
get
{
return false;
}
}
public bool IsMdiChild
{
get
{
return false;
}
}
public bool IsFloating
{
get
{
return false;
}
}
public Id<IView> ParentId
{
get
{
return Id<IView>.Empty;
}
}
public IController Controller
{
get
{
return null;
}
set
{
}
}
[field: NonSerialized]
public event EventHandler<EventArgs> Activated;
[field: NonSerialized]
public event EventHandler<EventArgs> Deactivated;
public bool SingleInstance
{
get
{
return false;
}
}
public void Close()
{
}
public void SetParent(IFormView parentView)
{
}
public void ChildOpening(Ingenious.Mvc.Windows.Forms.Views.IFormView childView)
{
}
public void ChildClosed(Ingenious.Mvc.Windows.Forms.Views.IFormView childView)
{
}
public void Show(bool modal)
{
}
public event EventHandler<EventArgs> Closed;
public Id<IView> Id
{
get
{
return Id<IView>.Empty;
}
set
{
}
}
public void Initialize()
{
}
public void SetData(object data)
{
}
public Task Task
{
get
{
return null;
}
set
{
}
}
}
#endregion
}
}
|