Hi all,
I'm implementing the DB testing of my application, that uses NHibernate as
persistence method.
I like the RollBack attribute of MbUnit because I cannot use a real dev DB,
but I can only work on the "testing" db, and I cannot put real data on it.
But it doesn't work with NHibernate.
let me explain with 2 different examples:
1 - Plain test as I used to do using a "normal" Ado repository
[TestFixture]
[TestsOn(typeof(UsersPersistenceService))]
public class UserPersistenceFixtures
{
UsersPersistenceService _service;
[SetUp]
public void SetUp()
{
_service = new UsersPersistenceService();
}
[Test]
[RollBack]
public void AddUser()
{
User target = new User();
target.Name = "Name";
target.EmailAddress = "[EMAIL PROTECTED]";
_service.Add(target);
User newUser = _service.GetById(target.Id);
Assert.AreEqual(target.Id, newUser.Id);
Assert.AreEqual("Name", newUser.Name);
}
[TearDown]
public void TearDown()
{
NHibernateSessionManager.Instance.CloseSession();
}
I get the error:
System.Runtime.InteropServices.COMException
The partner transaction manager has disabled its support for remote/network
transactions. (Exception from HRESULT: 0x8004D025)
and the test is never executed
2 - Open a transaction context on the current NH session
[TestFixture]
[TestsOn(typeof(UsersPersistenceService))]
public class UserPersistenceFixtures
{
UsersPersistenceService _service;
[SetUp]
public void SetUp()
{
NHibernateSessionManager.Instance.BeginTransaction();
_service = new UsersPersistenceService();
}
[Test]
[RollBack]
public void AddUser()
{
User target = new User();
target.Name = "Name";
target.EmailAddress = "[EMAIL PROTECTED]";
_service.Add(target);
User newUser = _service.GetById(target.Id);
Assert.AreEqual(target.Id, newUser.Id);
Assert.AreEqual("Name", newUser.Name);
}
[TearDown]
public void TearDown()
{
NHibernateSessionManager.Instance.CommitTransaction();
NHibernateSessionManager.Instance.CloseSession();
}
The test executes, but the data are store to the db.
Any idea on how to make it work? Shouldn't the MbUnit rollback happen before
the commit, so rolling back the transaction before the commit happens?
Cheers
Simone
--
Simone Chiaretta
codeclimber.net.nz
Any sufficiently advanced technology is indistinguishable from magic
"Life is short, play hard"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---