public static void TestCase_FailPromotableSinglePhaseNotificationCalls()
{
string testCaseDescription = "TestCase_FailPromotableSinglePhaseNotificationCalls";
Trace("**** " + testCaseDescription + " ****");
AutoResetEvent pspeCompleted = new AutoResetEvent(false);
NonMSDTCPromoterEnlistment pspe = null;
Trace("Fail Initialize");
try
{
using (TransactionScope ts = new TransactionScope())
{
pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
NonMsdtcPromoterTests.PromotedToken1,
pspeCompleted,
/*nonMSDTC = */ true,
/*tx = */ null,
/*spcResponse=*/ TransactionStatus.Committed,
/*expectRejection=*/ false,
/*comparePromotedToken=*/ false,
/*failInitialize=*/ true,
/*failPromote=*/ false,
/*failSPC=*/ false,
/*failGetPromoterType=*/ false,
/*failGetId=*/ false
);
bool shouldNotBeExecuted = true;
Assert.False(shouldNotBeExecuted);
}
}
catch (Exception ex)
{
Assert.True(ex is ApplicationException || (ex is TargetInvocationException && ex.InnerException is ApplicationException));
}
Trace("Fail Promote");
try
{
using (TransactionScope ts = new TransactionScope())
{
pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
NonMsdtcPromoterTests.PromotedToken1,
pspeCompleted,
/*nonMSDTC = */ true,
/*tx = */ null,
/*spcResponse=*/ TransactionStatus.Committed,
/*expectRejection=*/ false,
/*comparePromotedToken=*/ false,
/*failInitialize=*/ false,
/*failPromote=*/ true,
/*failSPC=*/ false,
/*failGetPromoterType=*/ false,
/*failGetId=*/ false
);
Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1);
ts.Complete();
}
}
catch (Exception ex)
{
Assert.True(ex is ApplicationException || (ex is TargetInvocationException && ex.InnerException is ApplicationException));
}
// The NonMSDTCPromoterEnlistment is coded to set "Promoted" at the beginning of Promote, before
// throwing.
Assert.True(pspeCompleted.WaitOne(TimeSpan.FromSeconds(5)));
Assert.True(pspe.Promoted);
Trace("Fail SinglePhaseCommit");
try
{
using (TransactionScope ts = new TransactionScope())
{
pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
NonMsdtcPromoterTests.PromotedToken1,
pspeCompleted,
/*nonMSDTC = */ true,
/*tx = */ null,
/*spcResponse=*/ TransactionStatus.Committed,
/*expectRejection=*/ false,
/*comparePromotedToken=*/ false,
/*failInitialize=*/ false,
/*failPromote=*/ false,
/*failSPC=*/ true,
/*failGetPromoterType=*/ false,
/*failGetId=*/ false
);
Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1);
ts.Complete();
}
}
catch (Exception ex)
{
Assert.True(ex is ApplicationException || (ex is TargetInvocationException && ex.InnerException is ApplicationException));
}
// The NonMSDTCPromoterEnlistment is coded to set "Promoted" at the beginning of Promote, before
// throwing.
Assert.True(pspeCompleted.WaitOne(TimeSpan.FromSeconds(5)));
Assert.True(pspe.Promoted);
TestPassed();
}