Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/CfgTest
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21222/src/NHibernate.Test/CfgTest
Modified Files:
ConfigurationFixture.cs
Log Message:
NH-207: readers clean up after themselves.
Index: ConfigurationFixture.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationFixture.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ConfigurationFixture.cs 28 Sep 2004 01:09:18 -0000 1.8
--- ConfigurationFixture.cs 21 Feb 2005 14:27:36 -0000 1.9
***************
*** 1,4 ****
--- 1,6 ----
using System;
using System.Collections;
+ using System.IO;
+ using System.Xml;
using NHibernate.Cfg;
***************
*** 74,78 ****
--- 76,150 ----
}
+ /// <summary>
+ /// Verify that NHibernate properly releases resources when an Exception occurs
+ /// during the reading of config files.
+ /// </summary>
+ [Test]
+ public void InvalidXmlInCfgFile()
+ {
+ XmlDocument cfgXml = new XmlDocument();
+ cfgXml.Load( "hibernate.cfg.xml" );
+
+ // this should put us at the first <property> element
+ XmlElement propElement = cfgXml.DocumentElement.GetElementsByTagName( "property" )[0] as XmlElement;
+
+ // removing this will cause it not to validate
+ propElement.RemoveAttribute( "name" );
+
+ cfgXml.Save( "hibernate.invalid.cfg.xml" );
+
+ Configuration cfg = new Configuration();
+ try
+ {
+ cfg.Configure( "hibernate.invalid.cfg.xml" );
+ }
+ catch( HibernateException )
+ {
+ // just absorb it - not what we are testing
+ }
+ finally
+ {
+ // clean up the bad file - if the Configure method cleans up after
+ // itself we should be able to do this without problem. If it does
+ // property release the resource then this won't be able to access
+ // the file to delete.
+ System.IO.File.Delete( "hibernate.invalid.cfg.xml" );
+ }
+
+ }
+
+ [Test]
+ public void InvalidXmlInHbmFile()
+ {
+ string filename = "invalid.hbm.xml";
+ // it's missing the class name - won't validate
+ string hbm = @"<?xml version='1.0' encoding='utf-8' ?>
+ <hibernate-mapping xmlns='urn:nhibernate-mapping-2.0'>
+ <class table='a'></class>
+ </hibernate-mapping>";
+ XmlDocument hbmDoc = new XmlDocument();
+ hbmDoc.LoadXml( hbm );
+ hbmDoc.Save( filename );
+
+ Configuration cfg = new Configuration();
+ try
+ {
+ cfg.Configure();
+ cfg.AddXmlFile( "invalid.hbm.xml" );
+ }
+ catch( HibernateException )
+ {
+ // just absorb it - not what we are testing
+ }
+ finally
+ {
+ // clean up the bad file - if the AddXmlFile method cleans up after
+ // itself we should be able to do this without problem. If it does
+ // property release the resource then this won't be able to access
+ // the file to delete.
+ System.IO.File.Delete( filename );
+ }
+ }
}
}
|