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

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

public static TestCase_SetDistributedIdAtWrongTime ( ) : void
Результат void
        public static void TestCase_SetDistributedIdAtWrongTime()
        {
            string testCaseDescription = "TestCase_SetDistributedIdAtWrongTime";

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

            AutoResetEvent pspeCompleted = new AutoResetEvent(false);
            NonMSDTCPromoterEnlistment pspe = null;
            NonMSDTCPromoterEnlistment dummyPSPE = new NonMSDTCPromoterEnlistment(NonMsdtcPromoterTests.PromoterType1, NonMsdtcPromoterTests.PromotedToken1, pspeCompleted);

            Guid guidToSet = new Guid("236BC646-FE3B-41F9-99F7-08BF448D8420");

            using (TransactionScope ts = new TransactionScope())
            {
                Trace("Before EnlistPromotable");
                Exception ex = Assert.ThrowsAny<Exception>(() => SetDistributedTransactionId(dummyPSPE, Transaction.Current, guidToSet));
                Assert.True(ex is TransactionException || (ex is TargetInvocationException && ex.InnerException is TransactionException));

                pspe = (NonMSDTCPromoterEnlistment)CreatePSPEEnlistment(NonMsdtcPromoterTests.PromoterType1,
                    NonMsdtcPromoterTests.PromotedToken1,
                    pspeCompleted,
                    /*nonMSDTC = */ true,
                    /*tx = */ null,
                    /*spcResponse=*/ TransactionStatus.Committed,
                    /*expectRejection=*/ false,
                    /*comparePromotedToken=*/ false,
                    /*failInitialize=*/ false,
                    /*failPromote=*/ false,
                    /*failSPC=*/ false,
                    /*failGetPromoterType=*/ false,
                    /*failGetId=*/ false
                    );

                Trace("After EnlistPromotable");
                ex = Assert.ThrowsAny<Exception>(() => SetDistributedTransactionId(dummyPSPE, Transaction.Current, guidToSet));
                Assert.True(ex is TransactionException || (ex is TargetInvocationException && ex.InnerException is TransactionException));

                Promote(testCaseDescription, NonMsdtcPromoterTests.PromotedToken1);

                Trace("After Promotion");
                ex = Assert.ThrowsAny<Exception>(() => SetDistributedTransactionId(dummyPSPE, Transaction.Current, guidToSet));
                Assert.True(ex is TransactionException || (ex is TargetInvocationException && ex.InnerException is TransactionException));

                ts.Complete();
            }

            // 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();
        }
NonMsdtcPromoterTests