#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.Reflection;
using System.Resources;
using System.Xml;
using NUnit.Framework;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.Configuration.Configurators;
using Ingenious.Mvc.Factories;
using Ingenious.Mvc.Navigators;
namespace Ingenious.Mvc.UnitTest.Navigators{
/// <summary>
/// Unit tests the <see cref="OpenNavigatorXmlCustomParser"/> class.
/// </summary>
public sealed class OpenNavigatorXmlCustomParserTest : UnitTestBase
{
private IXmlCustomParser _parser;
private NavigatorInfo _navigatorInfo;
protected override void SetUp()
{
//have to create parser indirectly since it is an internal class
XmlCustomParserAttribute attribute = (XmlCustomParserAttribute) typeof(OpenNavigator).GetCustomAttributes(typeof(XmlCustomParserAttribute), true)[0];
_parser = attribute.GetXmlCustomParser();
_navigatorInfo = new NavigatorInfo("test");
TaskManager.ConfigurationInfo = new ConfigurationInfo();
TaskManager.ConfigurationInfo.NavigatorInfos.Add(_navigatorInfo);
TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("Logon"));
TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("AddClient"));
TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("About"));
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullConfigurationInfo()
{
_parser.Parse(null, null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullParent()
{
_parser.Parse(TaskManager.ConfigurationInfo, null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullSection()
{
_parser.Parse(TaskManager.ConfigurationInfo, _navigatorInfo, null);
}
[Test]
[ExpectedException(typeof(ConfigurationException), "The parent object passed into the Create method must be of type 'Ingenious.Mvc.Configuration.NavigatorInfo', but it is of type 'System.String'.")]
public void TestWrongParentType()
{
_parser.Parse(TaskManager.ConfigurationInfo, string.Empty, GetResourceAsXml("SingleView"));
}
[Test]
public void TestEmpty()
{
IdCollection<Id<IView>> viewIds = ParseConfiguration("Empty");
Assert.IsNotNull(viewIds);
Assert.AreEqual(0, viewIds.Count);
Assert.IsNull(_navigatorInfo.StartViewInfo);
}
[Test]
public void TestEmptyExplicitStartingView()
{
_navigatorInfo.StartViewInfo = new ViewInfo("About");
IdCollection<Id<IView>> viewIds = ParseConfiguration("Empty");
Assert.IsNotNull(viewIds);
Assert.AreEqual(0, viewIds.Count);
Assert.AreEqual("About", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestSingleView()
{
IdCollection<Id<IView>> viewIds = ParseConfiguration("SingleView");
Assert.IsNotNull(viewIds);
Assert.AreEqual(1, viewIds.Count);
Assert.AreEqual("Logon", viewIds[0].ToString());
Assert.IsNotNull(_navigatorInfo.StartViewInfo);
Assert.AreEqual("Logon", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleViews()
{
IdCollection<Id<IView>> viewIds = ParseConfiguration("MultipleViews");
Assert.IsNotNull(viewIds);
Assert.AreEqual(3, viewIds.Count);
Assert.AreEqual("Logon", viewIds[0].ToString());
Assert.AreEqual("AddClient", viewIds[1].ToString());
Assert.AreEqual("About", viewIds[2].ToString());
Assert.IsNotNull(_navigatorInfo.StartViewInfo);
Assert.AreEqual("Logon", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleViewsExplicitStartingView()
{
_navigatorInfo.StartViewInfo = new ViewInfo("About");
IdCollection<Id<IView>> viewIds = ParseConfiguration("MultipleViews");
Assert.IsNotNull(viewIds);
Assert.AreEqual(3, viewIds.Count);
Assert.AreEqual("Logon", viewIds[0].ToString());
Assert.AreEqual("AddClient", viewIds[1].ToString());
Assert.AreEqual("About", viewIds[2].ToString());
Assert.IsNotNull(_navigatorInfo.StartViewInfo);
Assert.AreEqual("About", _navigatorInfo.StartViewInfo.Id.ToString());
}
private IdCollection<Id<IView>> ParseConfiguration(string key)
{
return _parser.Parse(TaskManager.ConfigurationInfo, _navigatorInfo, GetResourceAsXml(key)) as IdCollection<Id<IView>>;
}
}
}
|