#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.Xml;
using System.Xml.Schema;
using NUnit.Framework;
using Ingenious.Mvc.Configuration;
using Ingenious.Mvc.Configuration.Configurators;
namespace Ingenious.Mvc.UnitTest.Configuration.Configurators{
/// <summary>
/// Unit tests the <see cref="XmlCustomParserAttribute"/> class.
/// </summary>
public sealed class XmlCustomParserAttributeTest : UnitTestBase
{
private XmlCustomParserAttribute _attribute;
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void TestNullType()
{
_attribute = new XmlCustomParserAttribute(null);
}
[Test]
[ExpectedException(typeof(ConfigurationException), "The specified type ('Ingenious.Mvc.UnitTest.Configuration.Configurators.XmlCustomParserAttributeTest') does not implement the interface 'Ingenious.Mvc.Configuration.Configurators.IXmlCustomParser', which is required in order to be used as a custom parser.")]
public void TestTypeDoesntImplementInterface()
{
_attribute = new XmlCustomParserAttribute(GetType());
}
[Test]
[ExpectedException(typeof(ConfigurationException), "The specified type ('Ingenious.Mvc.UnitTest.Configuration.Configurators.XmlCustomParserAttributeTest+CustomParserNoDefaultConstructor') does not have a default constructor, which is required in order to be used as a custom parser.")]
public void TestTypeDoesntHaveDefaultConsructor()
{
_attribute = new XmlCustomParserAttribute(typeof(CustomParserNoDefaultConstructor));
}
[Test]
public void TestValid()
{
_attribute = new XmlCustomParserAttribute(typeof(CustomParserValid));
Assert.AreEqual(typeof(CustomParserValid), _attribute.Type);
Assert.AreEqual("myCustomConfig", _attribute.GetXmlCustomParser().Parse(null, null, null));
}
#region Supporting Types
private sealed class CustomParserNoDefaultConstructor : IXmlCustomParser
{
public XmlSchema Schema
{
get
{
return null;
}
}
public string TypeName
{
get
{
return null;
}
}
public CustomParserNoDefaultConstructor(int dummy)
{
}
public object Parse(ConfigurationInfo configurationInfo, object parent, XmlNode section)
{
return null;
}
}
private sealed class CustomParserValid : IXmlCustomParser
{
public XmlSchema Schema
{
get
{
return null;
}
}
public string TypeName
{
get
{
return null;
}
}
public object Parse(ConfigurationInfo configurationInfo, object parent, XmlNode section)
{
return "myCustomConfig";
}
}
#endregion
}
}
|