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

TestCase_VolatileEnlistments() приватный статический Метод

private static TestCase_VolatileEnlistments ( int count, TransactionStatus expectedOutcome, EnlistmentOptions options = EnlistmentOptions.None, bool commitTx = true, bool votePrepared = true, Type expectedExceptionType = null ) : void
count int
expectedOutcome TransactionStatus
options EnlistmentOptions
commitTx bool
votePrepared bool
expectedExceptionType Type
Результат void
        private static void TestCase_VolatileEnlistments(
            int count,
            TransactionStatus expectedOutcome,
            EnlistmentOptions options = EnlistmentOptions.None,
            bool commitTx = true,
            bool votePrepared = true,
            Type expectedExceptionType = null)
        {
            string testCaseDescription = string.Format("TestCase_VolatileEnlistments; count = {0}; expectedOutcome = {1}; options = {2}; votePrepared = {3}, expectedExceptionType = {4}",
                        count,
                        expectedOutcome.ToString(),
                        options.ToString(),
                        votePrepared,
                        expectedExceptionType);

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

            AutoResetEvent[] enlistmentDoneEvts = new AutoResetEvent[count];
            MyEnlistment[] vols = new MyEnlistment[count];
            for (int i = 0; i < count; i++)
            {
                enlistmentDoneEvts[i] = new AutoResetEvent(false);
            }

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    for (int i = 0; i < count; i++)
                    {
                        vols[i] = CreateVolatileEnlistment(enlistmentDoneEvts[i], null, options, votePrepared);
                    }
                    if (commitTx)
                    {
                        ts.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Equal(expectedExceptionType, ex.GetType());
            }

            for (int i = 0; i < count; i++)
            {
                Assert.True(enlistmentDoneEvts[i].WaitOne(TimeSpan.FromSeconds(5)));
            }

            int passCount = 0;
            for (int i = 0; i < count; i++)
            {
                if (((expectedOutcome == TransactionStatus.Committed) && vols[i].CommittedOutcome) ||
                    ((expectedOutcome == TransactionStatus.Aborted) && vols[i].AbortedOutcome) ||
                    ((expectedOutcome == TransactionStatus.InDoubt) && vols[i].InDoubtOutcome)
                    )
                {
                    passCount++;
                }
            }
            Assert.Equal(count, passCount);

            TestPassed();
        }
NonMsdtcPromoterTests