Note that there are some explanatory texts on larger screens.

plurals
  1. PONesting transaction scopes for integration tests using Rhino Commons UnitOfWork
    text
    copied!<p>I'm trying to set up a integration test class that wraps each test in a transaction. This way I can rollback the transaction after each test instead of resetting the DB before each test.</p> <p>I also want to be able to use transactions in the integration tests themselves.</p> <p>I am using NHibernate and the Rhino Commons UnitOfWork for the the project. I am using MSTest for the tests.</p> <p>I want something like this:</p> <pre><code>[TestInitialize] public void TestInit() { // create outer transaction scope UnitOfWork.Start(); UnitOfWork.Current.BeginTransaction(); } [TestCleanup] public void TestCleanup() { // rollback outer transaction UnitOfWork.Current.Dispose(); } [TestMethod] public void IntegrationTest() { using (UnitOfWork.Start(UnitOfWorkNestingOptions.CreateNewOrNestUnitOfWork)) { UnitOfWork.Current.BeginTransaction(); // integration test code UnitOfWork.Current.TransactionalFlush(); // possibly more transactions } } </code></pre> <p>This is the first time I have used NHibernate, Rhino Commons, and MSTest. I am not clear on the behavior of sessions with nested Rhino Commons <code>UnitOfWork</code>s. What I have here does not rollback the changes from the integration test.</p> <p>I tried using <code>TransactionScope</code> from <code>System.Transactions</code>, but get the following error when the <code>UnitOfWork</code>s end:</p> <blockquote> <p>System.InvalidOperationException: Disconnect cannot be called while a transaction is in progress..</p> </blockquote> <p>So here are my questions:<br> Is there a way to get this behavior with UnitOfWork in Rhino Commons? If not, should I just reset the database before each test or is there another way to nest transactions that plays nicely with the UnitOfWork?</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload