public static void TestCase_AbortFromVolatile(bool promote, EnlistmentOptions enlistmentOptions = EnlistmentOptions.None)
{
string testCaseDescription = string.Format(
"TestCase_AbortFromVolatile promote={0}; enlistmentOptions = {1}",
promote,
enlistmentOptions.ToString()
);
Trace("**** " + testCaseDescription + " ****");
AutoResetEvent volCompleted = new AutoResetEvent(false);
AutoResetEvent pspeCompleted = new AutoResetEvent(false);
MyEnlistment vol = null;
NonMSDTCPromoterEnlistment pspe = null;
Assert.Throws<TransactionAbortedException>(() =>
{
using (TransactionScope ts = new TransactionScope())
{
vol = CreateVolatileEnlistment(volCompleted, null, enlistmentOptions, false);
pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
NonMsdtcPromoterTests.PromotedToken1,
pspeCompleted,
/*nonMSDTC = */ true,
/*tx = */ null,
/*spcResponse=*/ TransactionStatus.Committed,
/*expectRejection=*/ false
);
if (promote)
{
Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1);
}
ts.Complete();
}
});
Assert.True(volCompleted.WaitOne(TimeSpan.FromSeconds(5)) && pspeCompleted.WaitOne(TimeSpan.FromSeconds(5)));
Assert.True(vol.AbortedOutcome);
if (promote)
{
Assert.True(pspe.Promoted);
}
else
{
Assert.False(pspe.Promoted);
}
Assert.True(pspe.Aborted);
TestPassed();
}