public static void TestCase_EnlistDuringPrepare(bool promote,
bool beforePromote,
EnlistmentOptions firstOptions = EnlistmentOptions.None,
EnlistmentOptions secondOptions = EnlistmentOptions.None,
bool expectSecondEnlistSuccess = true
)
{
string testCaseDescription = string.Format(
"TestCase_EnlistDuringPrepare promote={0}; beforePromote={1}, firstOptions={2}, secondOptions={3}, expectSecondEnlistSuccess={4}",
promote,
beforePromote,
firstOptions.ToString(),
secondOptions.ToString(),
expectSecondEnlistSuccess
);
Trace("**** " + testCaseDescription + " ****");
AutoResetEvent volCompleted = new AutoResetEvent(false);
AutoResetEvent vol2Completed = new AutoResetEvent(false);
AutoResetEvent pspeCompleted = new AutoResetEvent(false);
MyEnlistment vol = null;
NonMSDTCPromoterEnlistment pspe = null;
try
{
using (TransactionScope ts = new TransactionScope())
{
if (beforePromote)
{
vol = new MyEnlistment(
volCompleted,
true,
true,
secondOptions,
/*expectSuccessfulEnlist=*/ expectSecondEnlistSuccess,
vol2Completed);
vol.TransactionToEnlist = Transaction.Current;
Transaction.Current.EnlistVolatile(vol, firstOptions);
}
pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
NonMsdtcPromoterTests.PromotedToken1,
pspeCompleted,
/*nonMSDTC = */ true,
/*tx = */ null,
/*spcResponse=*/ TransactionStatus.Committed,
/*expectRejection=*/ false
);
if (promote)
{
Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1);
if (!beforePromote)
{
vol = new MyEnlistment(
volCompleted,
true,
true,
secondOptions,
/*expectSuccessfulEnlist=*/ expectSecondEnlistSuccess,
vol2Completed);
vol.TransactionToEnlist = Transaction.Current;
Transaction.Current.EnlistVolatile(vol, firstOptions);
}
}
ts.Complete();
}
}
catch (Exception ex)
{
Assert.Null(ex);
}
if (!expectSecondEnlistSuccess)
{
vol2Completed.Set();
}
Assert.True(volCompleted.WaitOne(TimeSpan.FromSeconds(5)) && vol2Completed.WaitOne(TimeSpan.FromSeconds(5)) &&
pspeCompleted.WaitOne(TimeSpan.FromSeconds(5)));
Assert.False(vol.AbortedOutcome);
if (promote)
{
Assert.True(pspe.Promoted);
}
else
{
Assert.False(pspe.Promoted);
}
Assert.False(pspe.Aborted);
TestPassed();
}