|
From: <pa...@us...> - 2011-03-06 03:58:28
|
Revision: 5429
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5429&view=rev
Author: patearl
Date: 2011-03-06 03:58:22 +0000 (Sun, 06 Mar 2011)
Log Message:
-----------
TestCase: Added convenience method for running a SQL statement.
Join Tests: Prevent SQLite locking problems by reusing the same transaction. Fixed cleanup bug in join tests that started manifesting itself with a different id generation algorithm. Avoid dependence on cascade delete to clean up.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs
trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml
trunk/nhibernate/src/NHibernate.Test/TestCase.cs
Modified: trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs 2011-03-05 17:57:59 UTC (rev 5428)
+++ trunk/nhibernate/src/NHibernate.Test/Join/JoinTest.cs 2011-03-06 03:58:22 UTC (rev 5429)
@@ -133,7 +133,7 @@
s.Clear();
// Remove the optional row from the join table and requery the User obj
- ExecuteStatement("delete from t_user");
+ ExecuteStatement(s, tx, "delete from t_user");
s.Clear();
// Clean up the test data
@@ -171,7 +171,7 @@
}
}
- private Person PreparePersonWithInverseJoin(ISession s, string name, string stuffName)
+ private Person PreparePersonWithInverseJoin(ISession s, ITransaction tx, string name, string stuffName)
{
Person p = CreatePerson(name);
@@ -181,7 +181,7 @@
if (stuffName != null)
{
- int count = ExecuteStatement(
+ int count = ExecuteStatement(s, tx,
string.Format("insert into inversed_stuff (stuff_id, StuffName) values ({0}, '{1}')",
p.Id, stuffName));
Assert.AreEqual(1, count, "Insert statement failed.");
@@ -197,12 +197,14 @@
using (ITransaction tx = s.BeginTransaction())
{
string stuffName = "name of the stuff";
- Person p = PreparePersonWithInverseJoin(s, "John", stuffName);
+ Person p = PreparePersonWithInverseJoin(s, tx, "John", stuffName);
Person result = (Person) s.Get(typeof (Person), p.Id);
Assert.IsNotNull(result);
Assert.AreEqual(stuffName, result.StuffName);
+ ExecuteStatement(s, tx, "delete from inversed_stuff");
+
tx.Commit();
}
}
@@ -215,7 +217,7 @@
{
string stuffName = "name of the stuff";
- Person p = PreparePersonWithInverseJoin(s, "John", stuffName);
+ Person p = PreparePersonWithInverseJoin(s, tx, "John", stuffName);
Person personToUpdate = (Person) s.Get(typeof (Person), p.Id);
Assert.IsNotNull(personToUpdate);
@@ -227,6 +229,8 @@
Person loaded = (Person) s.Get(typeof (Person), p.Id);
Assert.AreEqual(stuffName, loaded.StuffName, "StuffName should not have been updated");
+ ExecuteStatement(s, tx, "delete from inversed_stuff");
+
tx.Commit();
}
}
@@ -259,7 +263,7 @@
using (ITransaction tx = s.BeginTransaction())
{
string stuffName = "stuff not deleted";
- Person p = PreparePersonWithInverseJoin(s, "John", stuffName);
+ Person p = PreparePersonWithInverseJoin(s, tx, "John", stuffName);
long personId = p.Id;
s.Delete(p);
@@ -282,6 +286,8 @@
string retrievedStuffName = (string) cmd2.ExecuteScalar();
Assert.AreEqual(stuffName, retrievedStuffName, "Retrieved inverse <join> does not match");
+ ExecuteStatement(s, tx, "delete from inversed_stuff");
+
tx.Commit();
}
}
Modified: trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml 2011-03-05 17:57:59 UTC (rev 5428)
+++ trunk/nhibernate/src/NHibernate.Test/Join/Person.hbm.xml 2011-03-06 03:58:22 UTC (rev 5429)
@@ -45,7 +45,7 @@
<property name="Salary"/>
<many-to-one name="Manager"/>
<bag name="Meetings" cascade="all" inverse="true" access="property">
- <key column="person_id" on-delete="cascade"/>
+ <key column="person_id"/>
<one-to-many class="Meeting"/>
</bag>
</join>
Modified: trunk/nhibernate/src/NHibernate.Test/TestCase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2011-03-05 17:57:59 UTC (rev 5428)
+++ trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2011-03-06 03:58:22 UTC (rev 5429)
@@ -285,6 +285,17 @@
}
}
+ public int ExecuteStatement(ISession session, ITransaction transaction, string sql)
+ {
+ using (IDbCommand cmd = session.Connection.CreateCommand())
+ {
+ cmd.CommandText = sql;
+ if (transaction != null)
+ transaction.Enlist(cmd);
+ return cmd.ExecuteNonQuery();
+ }
+ }
+
protected ISessionFactoryImplementor Sfi
{
get { return sessions; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|