#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 System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.Factories;
using Ingenious.Mvc.UnitTest.MockTypes;
namespace Ingenious.Mvc.UnitTest.Configuration{
/// <summary>
/// Unit tests the <see cref="ConfigurationInfo"/> type.
/// </summary>
public sealed class ConfigurationInfoTest : UnitTestBase
{
private ConfigurationInfo _configurationInfo;
protected override void SetUp()
{
_configurationInfo = new ConfigurationInfo();
}
[Test]
public void TestInitialisation()
{
Assert.IsNotNull(_configurationInfo.NavigatorInfos);
Assert.IsNotNull(_configurationInfo.ViewInfos);
Assert.AreEqual(DefaultControllerFactory.Instance, _configurationInfo.ControllerFactory);
Assert.AreEqual(DefaultNavigatorFactory.Instance, _configurationInfo.NavigatorFactory);
Assert.AreEqual(DefaultViewFactory.Instance, _configurationInfo.ViewFactory);
Assert.AreEqual(DefaultViewManagerFactory.Instance, _configurationInfo.ViewManagerFactory);
}
[Test]
public void TestSetFactory()
{
MockControllerFactory controllerFactory = new MockControllerFactory();
MockNavigatorFactory navigatorFactory = new MockNavigatorFactory();
MockViewFactory viewFactory = new MockViewFactory();
MockViewManagerFactory viewManagerFactory = new MockViewManagerFactory();
MockTaskFactory taskFactory = new MockTaskFactory();
_configurationInfo.ControllerFactory = controllerFactory;
_configurationInfo.NavigatorFactory = navigatorFactory;
_configurationInfo.ViewFactory = viewFactory;
_configurationInfo.ViewManagerFactory = viewManagerFactory;
_configurationInfo.TaskFactory = taskFactory;
Assert.AreEqual(controllerFactory, _configurationInfo.ControllerFactory);
Assert.AreEqual(navigatorFactory, _configurationInfo.NavigatorFactory);
Assert.AreEqual(viewFactory, _configurationInfo.ViewFactory);
Assert.AreEqual(viewManagerFactory, _configurationInfo.ViewManagerFactory);
Assert.AreEqual(taskFactory, _configurationInfo.TaskFactory);
}
[Test]
public void TestSerializationEmpty()
{
using (Stream stream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, _configurationInfo);
stream.Flush();
stream.Position = 0;
_configurationInfo = null;
_configurationInfo = (ConfigurationInfo) binaryFormatter.Deserialize(stream);
Assert.AreEqual(0, _configurationInfo.NavigatorInfos.Count);
Assert.AreEqual(0, _configurationInfo.ViewInfos.Count);
}
}
[Test]
public void TestSerializationFull()
{
using (Stream stream = new MemoryStream())
{
ViewManagerInfo viewManagerInfo = new ViewManagerInfo("viewManager");
viewManagerInfo.Type = typeof(MockViewManager);
for (int i = 0; i < 100; ++i)
{
string navId = "navigator" + i;
string viewId = "view" + i;
string controllerId = "controller" + i;
ControllerInfo controllerInfo = new ControllerInfo(controllerId);
controllerInfo.Type = typeof(MockController);
_configurationInfo.ViewInfos.Add(new ViewInfo(viewId));
_configurationInfo.ViewInfos[viewId].ControllerInfo = controllerInfo;
_configurationInfo.NavigatorInfos.Add(new NavigatorInfo(navId));
_configurationInfo.NavigatorInfos[navId].StartViewInfo = _configurationInfo.ViewInfos[viewId];
_configurationInfo.NavigatorInfos[navId].Type = typeof(MockNavigator);
_configurationInfo.NavigatorInfos[navId].ViewManagerInfo = viewManagerInfo;
}
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, _configurationInfo);
_configurationInfo = null;
stream.Flush();
stream.Position = 0;
_configurationInfo = (ConfigurationInfo) binaryFormatter.Deserialize(stream);
Assert.AreEqual(100, _configurationInfo.NavigatorInfos.Count);
Assert.AreEqual(100, _configurationInfo.ViewInfos.Count);
}
}
}
}
|