Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/MappingExceptions
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31654/MappingExceptions
Added Files:
A.ClassNotFound.hbm.xml A.cs A.Valid.hbm.xml
AddClassFixture.cs AddResourceFixture.cs AddXmlFileFixture.cs
Log Message:
Some test to verify exceptions being thrown correctly with a message.
--- NEW FILE: A.Valid.hbm.xml ---
<?xml version="1.0" encoding="utf-8" ?>
<!--
This is a valid mapping for A.
-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Test.MappingExceptions.A, NHibernate.Test">
<id name="Id">
<generator class="native" />
</id>
<property name="Name" />
</class>
</hibernate-mapping>
--- NEW FILE: AddXmlFileFixture.cs ---
using System;
namespace NHibernate.Test.MappingExceptions
{
/// <summary>
/// Summary description for AddXmlFileFixture.
/// </summary>
public class AddXmlFileFixture
{
public AddXmlFileFixture()
{
//
// TODO: Add constructor logic here
//
}
}
}
--- NEW FILE: AddClassFixture.cs ---
using System;
using NHibernate.Cfg;
using NUnit.Framework;
namespace NHibernate.Test.MappingExceptions
{
/// <summary>
/// Summary description for AddClassFixture.
/// </summary>
[TestFixture]
public class AddClassFixture
{
[Test]
public void ClassMissingMappingFile()
{
Configuration cfg = new Configuration();
try
{
cfg.AddClass( typeof(A) );
}
catch( MappingException me )
{
Assert.AreEqual( "Resource: " + typeof(A).FullName + ".hbm.xml not found", me.Message );
}
}
[Test]
public void AddClassNotFound()
{
Configuration cfg = new Configuration();
try
{
cfg.AddResource( "NHibernate.Test.MappingExceptions.A.ClassNotFound.hbm.xml", this.GetType().Assembly );
}
catch( MappingException me )
{
Assert.AreEqual( "persistent class not found", me.Message );
}
}
}
}
--- NEW FILE: AddResourceFixture.cs ---
using System;
using NHibernate.Cfg;
using NUnit.Framework;
namespace NHibernate.Test.MappingExceptions
{
/// <summary>
/// Summary description for AddResourceFixture.
/// </summary>
[TestFixture]
public class AddResourceFixture
{
[Test]
public void ResourceNotFound()
{
// add a resource that doesn't exist
string resource = "NHibernate.Test.MappingExceptions.A.DoesNotExists.hbm.xml";
Configuration cfg = new Configuration();
try
{
cfg.AddResource( resource, this.GetType().Assembly );
}
catch( MappingException me )
{
Assert.AreEqual( "Resource: " + resource + " not found", me.Message );
}
}
[Test]
public void AddDuplicateImport()
{
string resource = "NHibernate.Test.MappingExceptions.A.Valid.hbm.xml";
Configuration cfg = new Configuration();
try
{
// adding an import of "A" and then adding a class that has a
// name of "A" will cause a duplicate import problem. This can
// occur if two classes are in different namespaces but named the
// same and the auto-import attribute is not set to "false" for one
// of them.
cfg.Imports["A"] = "Some other class";
cfg.AddResource( resource, this.GetType().Assembly );
}
catch( MappingException me )
{
Assert.AreEqual( "duplicate import: A", me.Message );
}
}
}
}
--- NEW FILE: A.ClassNotFound.hbm.xml ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: A.cs ---
using System;
namespace NHibernate.Test.MappingExceptions
{
/// <summary>
/// Summary description for A.
/// </summary>
public class A
{
private int _id;
private string _name;
private A()
{
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
}
|