This may be too obvious; but I notice from your comment that your
ITransactionManager field instance is constructor injected, is your
unit-test invoking your class from that constructor?

On Nov 7, 12:00 pm, Matt Johnson <[email protected]> wrote:
> Ok, I found that once I resolve an ITransactionManager, I can get the
> current transaction and roll it back:
>
>   // constructor injected
>   private readonly ITransactionManager _transactionManager;
>
>   ...
>
>   [Transaction]
>   public void SomeMethod()
>   {
>     ...
>     _transactionManger.CurrentTransaction.Value.Rollback();
>   }
>
> This works fine in both a console app and a WCF service.  HOWEVER - it
> doesn't seem to work within a unit test!  The main reason I want a
> rollback option is so I can create unit tests for the data layer and
> roll back the transactions after the test so the database is left
> unmodified.  In a unit test (at least when using MSTest in
> VisualStudio), CurrentTransaction is null.  I can't figure out why!
>
> Any ideas?
> -Matt
>
> On Nov 4, 12:57 pm, Matt Johnson <[email protected]> wrote:
>
>
>
>
>
>
>
> > I'm trying out the AutoTx facility.  I have it working where I apply
> > the [Transaction] attribute to my class and it works great when I want
> > the transaction to commit if there are no exceptions.
>
> > But how do I explicitly get the transaction to roll back without
> > throwing an exception?  Where is the transaction context?
>
> > I would have thought Session.Transaction.Rollback() would work, but
> > it's not the same transaction.
>
> > Thanks!
> > -Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en.

Reply via email to