#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;
using Ingenious.Mvc.Windows.Forms.Views;
namespace Ingenious.Mvc.UnitTest.Windows.Forms.Views{
/// <summary>
/// Unit tests the <see cref="WizardFormXmlCustomParser"/> class.
/// </summary>
public sealed class WizardFormXmlCustomParserTest : UnitTestBase
{
private IXmlCustomParser _parser;
protected override void SetUp()
{
//have to create parser indirectly since it is an internal class
XmlCustomParserAttribute attribute = (XmlCustomParserAttribute) typeof(WizardForm).GetCustomAttributes(typeof(XmlCustomParserAttribute), true)[0];
_parser = attribute.GetXmlCustomParser();
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullParent()
{
_parser.Parse(null, null, null);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullSection()
{
_parser.Parse(null, new ViewInfo("view"), null);
}
[Test]
public void TestEmpty()
{
WizardForm.CustomConfiguration customConfig = ParseConfiguration("Empty");
Assert.IsNull(customConfig.Title);
Assert.IsNull(customConfig.PreviousText);
Assert.IsNull(customConfig.NextText);
Assert.IsNull(customConfig.FinishText);
Assert.IsNull(customConfig.CancelText);
Assert.IsNull(customConfig.Image);
}
[Test]
public void TestNoImage()
{
WizardForm.CustomConfiguration customConfig = ParseConfiguration("NoImage");
Assert.AreEqual("myTitle", customConfig.Title);
Assert.AreEqual("myPreviousText", customConfig.PreviousText);
Assert.AreEqual("myNextText", customConfig.NextText);
Assert.AreEqual("myFinishText", customConfig.FinishText);
Assert.AreEqual("myCancelText", customConfig.CancelText);
Assert.IsNull(customConfig.Image);
}
[Test]
[ExpectedException(typeof(ConfigurationException), "No image resource or file could be found under 'foobar' for the view with ID 'view'.")]
public void TestImageNotFound()
{
ParseConfiguration("ImageNotFound");
}
[Test]
public void TestResourceImage()
{
WizardForm.CustomConfiguration customConfig = ParseConfiguration("ResourceImage");
Assert.IsNull(customConfig.Title);
Assert.IsNull(customConfig.PreviousText);
Assert.IsNull(customConfig.NextText);
Assert.IsNull(customConfig.FinishText);
Assert.IsNull(customConfig.CancelText);
Assert.IsNotNull(customConfig.Image);
Assert.AreEqual(100, customConfig.Image.Width);
Assert.AreEqual(275, customConfig.Image.Height);
}
[Test]
public void TestFileImage()
{
WizardForm.CustomConfiguration customConfig = ParseConfiguration("FileImage");
Assert.IsNull(customConfig.Title);
Assert.IsNull(customConfig.PreviousText);
Assert.IsNull(customConfig.NextText);
Assert.IsNull(customConfig.FinishText);
Assert.IsNull(customConfig.CancelText);
Assert.IsNotNull(customConfig.Image);
Assert.AreEqual(100, customConfig.Image.Width);
Assert.AreEqual(275, customConfig.Image.Height);
}
private WizardForm.CustomConfiguration ParseConfiguration(string key)
{
return _parser.Parse(TaskManager.ConfigurationInfo, new ViewInfo("view"), GetResourceAsXml(key)) as WizardForm.CustomConfiguration;
}
}
}
|