#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.ViewManagers;
using Ingenious.Mvc.UnitTest.MockTypes;
namespace Ingenious.Mvc.UnitTest.ViewManagers{
/// <summary>
/// Unit tests the <see cref="ViewManagerBase"/> class.
/// </summary>
public sealed class ViewManagerBaseTest : UnitTestBase
{
private ConcreteViewManager _viewManager;
protected override void SetUp()
{
Id<IViewManager> id = "vm";
_viewManager = new ConcreteViewManager(id, TaskManager);
}
[Test]
[ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IViewManager was illegally provided for argument 'id'.")]
public void TestConstructorIdEmpty()
{
_viewManager = new ConcreteViewManager(Id<IViewManager>.Empty, TaskManager);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestConstructorTaskManagerNull()
{
_viewManager = new ConcreteViewManager("vm", null);
}
[Test]
public void TestConstructor()
{
Id<IViewManager> id = "vm";
_viewManager = new ConcreteViewManager(id, TaskManager);
Assert.AreEqual(id, _viewManager.Id);
Assert.AreSame(TaskManager, _viewManager.TaskManager);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestActivateTaskNull1()
{
_viewManager.Activate(null, (string) null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestActivateTaskNull2()
{
_viewManager.Activate(null, (Enum) null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestActivateViewIdNull1()
{
_viewManager.Activate(CreateTask(), (string) null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestActivateViewIdNull2()
{
_viewManager.Activate(CreateTask(), (Enum) null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestCreateViewNullTask()
{
_viewManager.CreateView(null, "viewId");
}
[Test]
[ExpectedException(typeof(IdException), "An empty ID of type Ingenious.Mvc.IView was illegally provided for argument 'viewId'.")]
public void TestCreateViewViewIdEmpty()
{
_viewManager.CreateView(CreateTask(), Id<IView>.Empty);
}
[Test]
[ExpectedException(typeof(ViewManagerException), "No configuration has been supplied via the TaskManager.Configuration property.")]
public void TestCreateViewNoConfiguration()
{
_viewManager.CreateView(CreateTask(), "v");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "A view with ID 'v' could not be found.")]
public void TestCreateViewViewNotFound()
{
TaskManager.ConfigurationInfo = new ConfigurationInfo();
_viewManager.CreateView(CreateTask(), "v");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "There is no type specified for the view with ID 'v'.")]
public void TestCreateViewNoTypeForView()
{
TaskManager.ConfigurationInfo = new ConfigurationInfo();
TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("v"));
_viewManager.CreateView(CreateTask(), "v");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The view with ID 'v' has controller with ID 'c', but no type has been provided for the controller.")]
public void TestCreateViewNoTypeForController()
{
TaskManager.ConfigurationInfo = new ConfigurationInfo();
TaskManager.ConfigurationInfo.ViewFactory = new MockViewFactory();
ViewInfo viewInfo = new ViewInfo("v");
viewInfo.Type = typeof(MockView);
viewInfo.ControllerInfo = new ControllerInfo("c");
TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
_viewManager.CreateView(CreateTask(), "v");
}
[Test]
[ExpectedException(typeof(ViewManagerException), "The configured view factory failed to create a view instance for the view with ID 'v'.")]
public void TestCreateViewFactoryFailure()
{
TaskManager.ConfigurationInfo = new ConfigurationInfo();
TaskManager.ConfigurationInfo.ViewFactory = new MockViewFactory();
ViewInfo viewInfo = new ViewInfo("v");
viewInfo.Type = typeof(MockView);
viewInfo.ControllerInfo = new ControllerInfo("c");
viewInfo.ControllerInfo.Type = typeof(MockController);
TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
_viewManager.CreateView(CreateTask(), "v");
}
[Test]
public void TestValidNoController()
{
MockView view = new MockView();
MockViewFactory viewFactory = new MockViewFactory();
viewFactory.View = view;
TaskManager.ConfigurationInfo = new ConfigurationInfo();
TaskManager.ConfigurationInfo.ViewFactory = viewFactory;
ViewInfo viewInfo = new ViewInfo("v");
viewInfo.Type = typeof(MockView);
TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
NavigatorInfo navigatorInfo = new NavigatorInfo("n");
navigatorInfo.Type = typeof(MockNavigator);
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("vm");
viewManagerInfo.Type = typeof(Ingenious.Mvc.UnitTest.MockTypes.MockViewManager);
navigatorInfo.ViewManagerInfo = viewManagerInfo;
navigatorInfo.StartViewInfo = new ViewInfo("v");
TaskManager.ConfigurationInfo.NavigatorInfos.Add(navigatorInfo);
Task t = TaskManager.StartTask("n");
MockView createdView = (MockView) _viewManager.CreateView(t, "v");
Assert.IsNotNull(createdView);
Assert.IsNull(createdView.Controller);
}
[Test]
public void TestCreateViewValid()
{
MockView view = new MockView();
MockViewFactory viewFactory = new MockViewFactory();
viewFactory.View = view;
TaskManager.ConfigurationInfo = new ConfigurationInfo();
TaskManager.ConfigurationInfo.ViewFactory = viewFactory;
ViewInfo viewInfo = new ViewInfo("v");
viewInfo.Type = typeof(MockView);
viewInfo.ControllerInfo = new ControllerInfo("c");
viewInfo.ControllerInfo.Type = typeof(MockController);
TaskManager.ConfigurationInfo.ViewInfos.Add(viewInfo);
NavigatorInfo navigatorInfo = new NavigatorInfo("n");
navigatorInfo.Type = typeof(MockNavigator);
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("vm");
viewManagerInfo.Type = typeof(Ingenious.Mvc.UnitTest.MockTypes.MockViewManager);
navigatorInfo.ViewManagerInfo = viewManagerInfo;
navigatorInfo.StartViewInfo = new ViewInfo("v");
TaskManager.ConfigurationInfo.NavigatorInfos.Add(navigatorInfo);
Task t = TaskManager.StartTask("n");
IView createdView = _viewManager.CreateView(t, "v");
Assert.IsNotNull(createdView);
Assert.AreSame(view, createdView);
}
#region Supporting Types
private sealed class ConcreteViewManager : ViewManagerBase
{
public new TaskManager TaskManager
{
get
{
return base.TaskManager;
}
}
public ConcreteViewManager(Id<IViewManager> id, TaskManager taskManager) : base(id, taskManager)
{
}
public IView CreateView(Task task, Id<IView> viewId)
{
return ViewManagerBase.CreateView(task, viewId);
}
public override IView Activate(Task task, Id<IView> viewId, object viewData)
{
return null;
}
}
#endregion
}
}
|