Well there does seem to be an issue with the [Rollback] attribute of
MbUnit and how it interacts with NHibernates transactions.  I have it
on about 12 other tests that run just fine but as soon as I took it
off of this one it worked.  So that begs the question of how folks
implement unit testing and using a DAL.  I don't want to have to mock
everything as that seems to me that it would kill my productivity.
Any thoughts?

Josh

On Apr 6, 9:58 am, Will Shaver <[email protected]> wrote:
> Look at the one that runs previous to this one in your test runner.
> Only run just those two tests to see if you have an issue. At some
> point you're missing a rollback or some other session cleanup code.
>
> On Mon, Apr 6, 2009 at 7:54 AM, joshlrogers <[email protected]> wrote:
>
> > I believe it does wrap it, but this attribute works on all my other
> > tests that have this attribute and according to what I can reference
> > from MbUnit's documentation this should work fine.  In fact if I run
> > this test by itself it runs fine.  Now I understand (I learned that
> > lesson the first question I posed to this group) that might point to
> > another test causing issue, but this test is really independent of any
> > other test.  It creates its own group then deletes that same group it
> > isn't dependent on any other functionality.  Also if I take this test
> > out and run everything else it works fine.  It is just something to do
> > with this transaction but I the exception is EXTREMELY vague.
>
> > Thanks,
> > Josh
>
> > On Apr 6, 9:35 am, Will Shaver <[email protected]> wrote:
> >> What does the [Rollback] attribute do?
> >> Does it set up a session and a transaction? If so you're doing one
> >> transaction inside of another...
>
> >> On Mon, Apr 6, 2009 at 7:23 AM, joshlrogers <[email protected]> wrote:
>
> >> > I am running a test:
>
> >> >        [Test]
> >> >        [Rollback]
> >> >        public void CanDeleteRatingGroupByName()
> >> >        {
>
> >> >            CWTRatingGroup newGroup = new CWTRatingGroup();
> >> >            newGroup.Name = "Delete Me";
> >> >            newGroup.UserAdded = provider.GetUserById(1);
>
> >> >            int id = provider.AddCWTRatingGroup(newGroup);
>
> >> >            provider.RemoveCWTRatingGroupByName(newGroup.Name);
>
> >> >            Assert.IsNull(provider.GetCWTRatingGroupById(id));
> >> >        }
>
> >> > The line
>
> >> >           int id = provider.AddCWTRatingGroup(newGroup);
>
> >> > fails with the following exception:
>
> >> > NHibernate.TransactionException: Begin failed with SQL exception --->
> >> > System.Data.SqlClient.SqlException: Distributed transaction completed.
> >> > Either enlist this session in a new transaction or the NULL
> >> > transaction.
> >> >   at System.Data.SqlClient.SqlConnection.OnError(SqlException
> >> > exception, Boolean breakConnection)
> >> >   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
> >> > exception, Boolean breakConnection)
> >> >   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning
> >> > (TdsParserStateObject stateObj)
> >> >   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
> >> > SqlCommand cmdHandler, SqlDataReader dataStream,
> >> > BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
> >> > stateObj)
> >> >   at
> >> > System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest
> >> > (Byte[] buffer, TransactionManagerRequestType request, String
> >> > transactionName, TransactionManagerIsolationLevel isoLevel, Int32
> >> > timeout, SqlInternalTransaction transaction, TdsParserStateObject
> >> > stateObj, Boolean isDelegateControlRequest)
> >> >   at
> >> > System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon
> >> > (TransactionRequest transactionRequest, String transactionName,
> >> > IsolationLevel iso, SqlInternalTransaction internalTransaction,
> >> > Boolean isDelegateControlRequest)
> >> >   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction
> >> > (TransactionRequest transactionRequest, String name, IsolationLevel
> >> > iso, SqlInternalTransaction internalTransaction, Boolean
> >> > isDelegateControlRequest)
> >> >   at System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction
> >> > (IsolationLevel iso, String transactionName)
> >> >   at System.Data.SqlClient.SqlInternalConnection.BeginTransaction
> >> > (IsolationLevel iso)
> >> >   at System.Data.SqlClient.SqlConnection.BeginDbTransaction
> >> > (IsolationLevel isolationLevel)
> >> >   at
> >> > System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction
> >> > ()
> >> >   at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel
> >> > isolationLevel)
> >> >   --- End of inner exception stack trace ---
> >> >   at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel
> >> > isolationLevel)
> >> >   at NHibernate.Transaction.AdoTransaction.Begin()
> >> >   at TEAMSData.DataLayer.NHibernateDataProvider.AddCWTRatingGroup
> >> > (CWTRatingGroup ratingGroup) in C:\Source\TEAMS\TEAMS\TEAMSData
> >> > \DataLayer\NHibernateDataProvider.cs:line 62
> >> >   at
> >> > TEAMSDataUnitTests.CWTRatingGroupDeleteTests.CanDeleteRatingGroupByName
> >> > () in C:\Source\TEAMS\TEAMS\TEAMSUnitTests\CWTRatingGroupTests.cs:line
> >> > 164
>
> >> > What confuses me is that the function that this calls is called in
> >> > other tests successfully.  Here is that code just for clarity sake:
>
> >> >        public int AddCWTRatingGroup(CWTRatingGroup ratingGroup)
> >> >        {
>
> >> >            try
> >> >            {
> >> >                ratingGroup.DateAdded = DateTime.Now;
>
> >> >                session.Transaction.Begin();
>
> >> >                int id = (int)session.Save(ratingGroup);
> >> >                session.Flush();
>
> >> >                session.Transaction.Commit();
>
> >> >                return id;
> >> >            }
> >> >            catch (Exception)
> >> >            {
> >> >                if( session.Transaction.IsActive )
> >> >                    session.Transaction.Rollback();
>
> >> >                ResetSession();
> >> >                throw;
> >> >            }
>
> >> >        }
>
> >> > Session.Transaction.Begin() is what actually throws the exception in
> >> > this case.  However I am doing almost the exact same thing in another
> >> > test and it runs just fine.
>
> >> > Any ideas?
>
> >> > Thanks again,
> >> > Josh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to