#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.UnitTest.MockTypes;
namespace Ingenious.Mvc.UnitTest.Factories{
/// <summary>
/// Unit tests the <see cref="DefaultViewManagerFactory"/> class.
/// </summary>
public sealed class DefaultViewManagerFactoryTest : UnitTestBase
{
private TaskManager _taskManager;
private IViewManagerFactory _factory;
protected override void SetUp()
{
_taskManager = new TaskManager();
_factory = DefaultViewManagerFactory.Instance;
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullViewManager()
{
_factory.Create(null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullTaskManager()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
_factory.Create(viewManagerInfo, null);
}
[Test]
[ExpectedException(typeof(FactoryException), "There is no type specified for the view manager with ID 'Test'.")]
public void TestNullType()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
_factory.Create(viewManagerInfo, _taskManager);
}
[Test]
[ExpectedException(typeof(FactoryException), "No appropriate constructor on type 'Ingenious.Mvc.UnitTest.Factories.DefaultViewManagerFactoryTest+NoDefaultConstructor' was found as required by the 'Default View Manager' factory. You need either a default constructor or one accepting arguments (Ingenious.Mvc.Id`1[Ingenious.Mvc.IViewManager], Ingenious.Mvc.TaskManager).")]
public void TestNoDefaultConstructor()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
viewManagerInfo.Type = typeof(NoDefaultConstructor);
_factory.Create(viewManagerInfo, _taskManager);
}
[Test]
public void TestHasConstructor()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
viewManagerInfo.Type = typeof(HasConstructor);
HasConstructor viewManager = (HasConstructor) _factory.Create(viewManagerInfo, _taskManager);
Assert.IsNotNull(viewManager);
Assert.AreEqual(_taskManager, viewManager.TaskManager);
}
[Test]
public void TestHasProperties()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
viewManagerInfo.Type = typeof(HasProperties);
HasProperties viewManager = (HasProperties) _factory.Create(viewManagerInfo, _taskManager);
Assert.IsNotNull(viewManager);
Assert.AreEqual(_taskManager, viewManager.TaskManager);
}
[Test]
public void TestConfigurable()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
viewManagerInfo.Type = typeof(ConfigurableViewManager);
viewManagerInfo.CustomConfiguration = new object();
ConfigurableViewManager viewManager = (ConfigurableViewManager) _factory.Create(viewManagerInfo, _taskManager);
Assert.AreEqual(_taskManager, viewManager.TaskManager);
Assert.AreEqual(viewManagerInfo.CustomConfiguration, viewManager.CustomConfiguration);
}
[Test]
public void TestInitialize()
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("Test");
viewManagerInfo.Type = typeof(MockViewManager);
MockViewManager viewManager = (MockViewManager) _factory.Create(viewManagerInfo, _taskManager);
Assert.AreEqual(_taskManager, viewManager.TaskManager);
Assert.IsTrue(viewManager.Initialized);
}
#region Supporting Types
private sealed class DoesNotImplementIViewManager
{
}
private abstract class BaseViewManager : IViewManager
{
private Id<IViewManager> _id;
private IView _activeView;
public Id<IViewManager> Id
{
get
{
return _id;
}
set
{
_id = value;
}
}
public IView ActiveView
{
get
{
return _activeView;
}
set
{
_activeView = value;
}
}
public event EventHandler<ViewEventArgs> ViewActivated;
public event EventHandler<ViewEventArgs> ViewDeactivated;
public IView Activate(Task task, Id<IView> viewId, object viewData)
{
return null;
}
public void Initialize()
{
}
}
private sealed class NoDefaultConstructor : BaseViewManager
{
public NoDefaultConstructor(int whatThe)
{
}
}
private sealed class HasConstructor : BaseViewManager
{
private Id<IViewManager> _id;
private TaskManager _taskManager;
public new Id<IViewManager> Id
{
get
{
return _id;
}
}
public TaskManager TaskManager
{
get
{
return _taskManager;
}
}
public HasConstructor(Id<IViewManager> id, TaskManager taskManager)
{
_id = id;
_taskManager = taskManager;
}
}
private class HasProperties : BaseViewManager
{
private TaskManager _taskManager;
public TaskManager TaskManager
{
get
{
return _taskManager;
}
set
{
_taskManager = value;
}
}
}
private sealed class ConfigurableViewManager : HasProperties, ICustomConfigurable
{
private object _customConfiguration;
public object CustomConfiguration
{
get
{
return _customConfiguration;
}
}
public void SetCustomConfiguration(object customConfiguration)
{
_customConfiguration = customConfiguration;
}
}
#endregion
}
}
|