System.Transactions.Tests.NonMsdtcPromoterTests.TestCase_DisposeCommittableTransaction C# (CSharp) Метод

TestCase_DisposeCommittableTransaction() публичный статический Метод

public static TestCase_DisposeCommittableTransaction ( bool promote ) : void
promote bool
Результат void
        public static void TestCase_DisposeCommittableTransaction(bool promote)
        {
            string testCaseDescription = string.Format(
                "TestCase_DisposeCommittableTransaction promote={0}",
                promote
                );

            Trace("**** " + testCaseDescription + " ****");

            AutoResetEvent pspeCompleted = new AutoResetEvent(false);
            NonMSDTCPromoterEnlistment pspe = null;
            Transaction savedTransaction = null;

            try
            {
                CommittableTransaction tx = new CommittableTransaction(TimeSpan.FromMinutes(1));
                savedTransaction = tx.Clone();

                pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
                    NonMsdtcPromoterTests.PromotedToken1,
                    pspeCompleted,
                    /*nonMSDTC = */ true,
                    tx,
                    /*spcResponse=*/ TransactionStatus.Committed,
                    /*expectRejection=*/ false
                    );

                if (promote)
                {
                    Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1, tx);
                }

                tx.Dispose();

                tx.Commit();
            }
            catch (Exception ex)
            {
                Assert.IsType<ObjectDisposedException>(ex);
            }

            Assert.True(pspeCompleted.WaitOne(TimeSpan.FromSeconds(5)));

            if (promote)
            {
                Assert.True(pspe.Promoted);
            }
            else
            {
                Assert.False(pspe.Promoted);
            }

            Assert.True(pspe.Aborted);

            Assert.Equal(TransactionStatus.Aborted, savedTransaction.TransactionInformation.Status);

            TestPassed();
        }
NonMsdtcPromoterTests