I took a look at the original 1.1 implementation by Roy Osherove, and
tweaked it to use lightweight transactions via System. Transactions
instead. I've only had a chance to test on my local machine, but my
understanding is that the lightweight transaction will get promoted to
a full MSDTC based transaction automatically if necessary via the
ambient transaction context. Heres the code:
namespace MbUnit.Framework
{
using MbUnit.Core.Framework;
using MbUnit.Core.Invokers;
using System;
using System.Collections;
using System.Transactions;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false,
Inherited = true)]
public sealed class RollBackAttribute : DecoratorPatternAttribute
{
public override IRunInvoker GetInvoker(IRunInvoker invoker)
{
return new
MbUnit.Framework.RollBackAttribute.RollBackRunInvoker(invoker);
}
private class RollBackRunInvoker : DecoratorRunInvoker
{
private TransactionScope testscope;
public RollBackRunInvoker(IRunInvoker invoker)
: base(invoker)
{
}
private void AbortRunningTransaction()
{
testscope.Dispose();
}
private void CreateTransactionScope()
{
testscope = new
TransactionScope(TransactionScopeOption.RequiresNew);
}
public override object Execute(object o, IList args)
{
object obj2;
this.CreateTransactionScope();
try
{
object obj1 = base.Invoker.Execute(o, args);
obj2 = obj1;
}
finally
{
this.AbortRunningTransaction();
}
return obj2;
}
}
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---