#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="GraphNavigatorXmlCustomParser"/> class.
/// </summary>
public sealed class GraphNavigatorXmlCustomParserTest : 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(GraphNavigator).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("Main"));
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("SingleFromView"));
}
[Test]
public void TestSingleFromView()
{
GraphNavigator.CustomConfiguration aliases = ParseConfiguration("SingleFromView");
Assert.IsNotNull(aliases);
Assert.AreEqual(2, aliases.Count);
Assert.AreEqual("Logon", aliases[0].FromView.ToString());
Assert.AreEqual("Main", aliases[0].ToView.ToString());
Assert.AreEqual("Success", aliases[0].Alias.ToString());
Assert.AreEqual("Logon", aliases[1].FromView.ToString());
Assert.AreEqual("Logon", aliases[1].ToView.ToString());
Assert.AreEqual("Failure", aliases[1].Alias.ToString());
Assert.IsNotNull(_navigatorInfo.StartViewInfo);
Assert.AreEqual("Logon", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleFromViews()
{
GraphNavigator.CustomConfiguration aliases = ParseConfiguration("MultipleFromViews");
AssertMultipleFromViewsCommon(aliases);
Assert.IsNotNull(_navigatorInfo.StartViewInfo);
Assert.AreEqual("Logon", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleFromViewsExplicitStartingView()
{
_navigatorInfo.StartViewInfo = new ViewInfo("About");
GraphNavigator.CustomConfiguration aliases = ParseConfiguration("MultipleFromViews");
AssertMultipleFromViewsCommon(aliases);
Assert.IsNotNull(_navigatorInfo.StartViewInfo);
Assert.AreEqual("About", _navigatorInfo.StartViewInfo.Id.ToString());
}
private void AssertMultipleFromViewsCommon(GraphNavigator.CustomConfiguration aliases)
{
Assert.IsNotNull(aliases);
Assert.AreEqual(5, aliases.Count);
Assert.AreEqual("Logon", aliases[0].FromView.ToString());
Assert.AreEqual("Main", aliases[0].ToView.ToString());
Assert.AreEqual("Success", aliases[0].Alias.ToString());
Assert.AreEqual("Logon", aliases[1].FromView.ToString());
Assert.AreEqual("Logon", aliases[1].ToView.ToString());
Assert.AreEqual("Failure", aliases[1].Alias.ToString());
Assert.AreEqual("Main", aliases[2].FromView.ToString());
Assert.AreEqual("Logon", aliases[2].ToView.ToString());
Assert.AreEqual("Logoff", aliases[2].Alias.ToString());
Assert.AreEqual("Main", aliases[3].FromView.ToString());
Assert.AreEqual("AddClient", aliases[3].ToView.ToString());
Assert.AreEqual("AddClient", aliases[3].Alias.ToString());
Assert.AreEqual("Main", aliases[4].FromView.ToString());
Assert.AreEqual("About", aliases[4].ToView.ToString());
Assert.AreEqual("Help", aliases[4].Alias.ToString());
}
private GraphNavigator.CustomConfiguration ParseConfiguration(string key)
{
return _parser.Parse(TaskManager.ConfigurationInfo, _navigatorInfo, GetResourceAsXml(key)) as GraphNavigator.CustomConfiguration;
}
}
}
|