Revision: 5827
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5827&view=rev
Author: patearl
Date: 2011-05-16 00:08:36 +0000 (Mon, 16 May 2011)
Log Message:
-----------
Tests: Improved a DtcFailures test so it works on more databases.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2011-05-15 23:58:33 UTC (rev 5826)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2011-05-16 00:08:36 UTC (rev 5827)
@@ -1,9 +1,14 @@
using System;
using System.Collections;
+using System.Linq;
+using System.Reflection;
using System.Threading;
using System.Transactions;
using log4net;
using log4net.Repository.Hierarchy;
+using NHibernate.Cfg;
+using NHibernate.Cfg.MappingSchema;
+using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.DtcFailures
@@ -28,14 +33,39 @@
return TestDialect.GetTestDialect(dialect).SupportsDistributedTransactions;
}
+ protected override void CreateSchema()
+ {
+ // Copied from Configure method.
+ Configuration config = new Configuration();
+ if (TestConfigurationHelper.hibernateConfigFile != null)
+ config.Configure(TestConfigurationHelper.hibernateConfigFile);
+
+ // Our override so we can set nullability on database column without NHibernate knowing about it.
+ config.BeforeBindMapping += BeforeBindMapping;
+
+ // Copied from AddMappings methods.
+ Assembly assembly = Assembly.Load(MappingsAssembly);
+ foreach (string file in Mappings)
+ config.AddResource(MappingsAssembly + "." + file, assembly);
+
+ // Copied from CreateSchema method, but we use our own config.
+ new SchemaExport(config).Create(false, true);
+ }
+
+ private void BeforeBindMapping(object sender, BindMappingEventArgs e)
+ {
+ HbmProperty prop = e.Mapping.RootClasses[0].Properties.OfType<HbmProperty>().Single(p => p.Name == "NotNullData");
+ prop.notnull = true;
+ prop.notnullSpecified = true;
+ }
+
[Test]
public void WillNotCrashOnDtcPrepareFailure()
{
var tx = new TransactionScope();
using (ISession s = sessions.OpenSession())
{
- s.Save(new Person {CreatedAt = DateTime.MinValue // will cause SQL date failure
- });
+ s.Save(new Person {NotNullData = null}); // Cause a SQL not null constraint violation.
}
new ForceEscalationToDistributedTx();
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml 2011-05-15 23:58:33 UTC (rev 5826)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml 2011-05-16 00:08:36 UTC (rev 5827)
@@ -8,6 +8,6 @@
<generator class="hilo"/>
</id>
<property name="CreatedAt"/>
-
+ <property name="NotNullData"/> <!-- NOT NULL will be set on created schema directly to avoid NH checks. -->
</class>
</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs 2011-05-15 23:58:33 UTC (rev 5826)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs 2011-05-16 00:08:36 UTC (rev 5827)
@@ -7,6 +7,11 @@
{
private int id;
+ public Person()
+ {
+ NotNullData = "not-null";
+ }
+
public virtual DateTime CreatedAt { get; set; }
public virtual int Id
@@ -14,5 +19,7 @@
get { return id; }
set { id = value; }
}
+
+ public virtual string NotNullData { get; set; }
}
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|