#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="WizardNavigatorXmlCustomParser"/> class.
/// </summary>
public sealed class WizardNavigatorXmlCustomParserTest : 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(WizardNavigator).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("Welcome"));
TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("EnterDetails"));
TaskManager.ConfigurationInfo.ViewInfos.Add(new ViewInfo("Summary"));
}
[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 TestSingleView()
{
WizardNavigator.CustomConfiguration customConfig = ParseConfiguration("SingleView");
Assert.IsNotNull(customConfig);
Assert.AreEqual(1, customConfig.ViewIds.Count);
Assert.AreEqual(0, customConfig.Aliases.Count);
Assert.AreEqual("Welcome", customConfig.ViewIds[0].ToString());
Assert.AreEqual("Welcome", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleViews()
{
WizardNavigator.CustomConfiguration customConfig = ParseConfiguration("MultipleViews");
Assert.IsNotNull(customConfig);
Assert.AreEqual(3, customConfig.ViewIds.Count);
Assert.AreEqual(0, customConfig.Aliases.Count);
Assert.AreEqual("Welcome", customConfig.ViewIds[0].ToString());
Assert.AreEqual("EnterDetails", customConfig.ViewIds[1].ToString());
Assert.AreEqual("Summary", customConfig.ViewIds[2].ToString());
Assert.AreEqual("Welcome", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleViewsAndAliases()
{
WizardNavigator.CustomConfiguration customConfig = ParseConfiguration("MultipleViewsAndAliases");
AssertMultipleViewsAndAliasesCommon(customConfig);
Assert.AreEqual("Welcome", _navigatorInfo.StartViewInfo.Id.ToString());
}
[Test]
public void TestMultipleViewsAndAliasesExplicitStartingView()
{
_navigatorInfo.StartViewInfo = new ViewInfo("Summary");
WizardNavigator.CustomConfiguration customConfig = ParseConfiguration("MultipleViewsAndAliases");
AssertMultipleViewsAndAliasesCommon(customConfig);
Assert.AreEqual("Summary", _navigatorInfo.StartViewInfo.Id.ToString());
}
private void AssertMultipleViewsAndAliasesCommon(WizardNavigator.CustomConfiguration customConfig)
{
Assert.IsNotNull(customConfig);
Assert.AreEqual(3, customConfig.ViewIds.Count);
Assert.AreEqual(3, customConfig.Aliases.Count);
Assert.AreEqual("Welcome", customConfig.ViewIds[0].ToString());
Assert.AreEqual("EnterDetails", customConfig.ViewIds[1].ToString());
Assert.AreEqual("Summary", customConfig.ViewIds[2].ToString());
Assert.AreEqual("Welcome", customConfig.Aliases[0].FromView.ToString());
Assert.AreEqual("Summary", customConfig.Aliases[0].ToView.ToString());
Assert.AreEqual("SkipEnterDetails", customConfig.Aliases[0].Alias.ToString());
Assert.AreEqual("Welcome", customConfig.Aliases[1].FromView.ToString());
Assert.AreEqual("EnterDetails", customConfig.Aliases[1].ToView.ToString());
Assert.AreEqual("Pointless", customConfig.Aliases[1].Alias.ToString());
Assert.AreEqual("Summary", customConfig.Aliases[2].FromView.ToString());
Assert.AreEqual("Welcome", customConfig.Aliases[2].ToView.ToString());
Assert.AreEqual("StartAgain", customConfig.Aliases[2].Alias.ToString());
}
private WizardNavigator.CustomConfiguration ParseConfiguration(string key)
{
return _parser.Parse(TaskManager.ConfigurationInfo, _navigatorInfo, GetResourceAsXml(key)) as WizardNavigator.CustomConfiguration;
}
}
}
|