System.Transactions.Tests.NonMsdtcPromoterTests.TryProhibitedOperations C# (CSharp) Method

TryProhibitedOperations() private static method

private static TryProhibitedOperations ( Transaction tx, Guid expectedPromoterType ) : void
tx Transaction
expectedPromoterType Guid
return void
        private static void TryProhibitedOperations(Transaction tx, Guid expectedPromoterType)
        {
            // First make sure that we can do a simple clone. This should be allowed.
            tx.Clone();

            try
            {
                Trace("Attempting TransactionInterop.GetDtcTransaction");
                TransactionInterop.GetDtcTransaction(tx);
                throw new ApplicationException("TransactionInterop.GetDtcTransaction unexpectedly succeeded.");
            }
            catch (TransactionPromotionException ex)
            {
                if (TxPromoterType(tx) != expectedPromoterType)
                {
                    Trace(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                    throw new ApplicationException(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                }
            }

            try
            {
                Trace("Attempting TransactionInterop.GetExportCookie");
                byte[] dummyWhereabouts = new byte[1];
                TransactionInterop.GetExportCookie(tx, dummyWhereabouts);
                throw new ApplicationException("TransactionInterop.GetExportCookie unexpectedly succeeded.");
            }
            catch (TransactionPromotionException ex)
            {
                if (TxPromoterType(tx) != expectedPromoterType)
                {
                    Trace(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                    throw new ApplicationException(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                }
            }

            try
            {
                Trace("Attempting TransactionInterop.GetTransmitterPropagationToken");
                byte[] dummyWhereabouts = new byte[1];
                TransactionInterop.GetTransmitterPropagationToken(tx);
                throw new ApplicationException("TransactionInterop.GetTransmitterPropagationToken unexpectedly succeeded.");
            }
            catch (TransactionPromotionException ex)
            {
                if (TxPromoterType(tx) != expectedPromoterType)
                {
                    Trace(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                    throw new ApplicationException(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                }
            }

            try
            {
                Trace("Attempting EnlistDurable");
                DummyDurableEnlistment enlistment = new DummyDurableEnlistment();
                tx.EnlistDurable(new Guid("611653C3-8536-4158-A990-00A8EE08B195"), enlistment, EnlistmentOptions.None);
                throw new ApplicationException("EnlistDurable unexpectedly succeeded.");
            }
            catch (TransactionPromotionException ex)
            {
                if (TxPromoterType(tx) != expectedPromoterType)
                {
                    Trace(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                    throw new ApplicationException(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                }
            }

            try
            {
                Trace("Attempting EnlistDurableSPC");
                DummyDurableEnlistmentSPC enlistment = new DummyDurableEnlistmentSPC();
                tx.EnlistDurable(new Guid("611653C3-8536-4158-A990-00A8EE08B195"), enlistment, EnlistmentOptions.None);
                throw new ApplicationException("EnlistDurableSPC unexpectedly succeeded.");
            }
            catch (TransactionPromotionException ex)
            {
                if (TxPromoterType(tx) != expectedPromoterType)
                {
                    Trace(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                    throw new ApplicationException(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
                }
            }

            // TODO #9582: Uncomment once IFormatter and BinaryFormatter are available in .NET Core
            //try
            //{
            //    MemoryStream txStream = new MemoryStream();
            //    IFormatter formatter = new BinaryFormatter();
            //    formatter.Serialize(txStream, tx);
            //    throw new ApplicationException("Serialize of transaction unexpectedly succeeded.");
            //}
            //catch (TransactionPromotionException ex)
            //{
            //    if (TxPromoterType(tx) != expectedPromoterType)
            //    {
            //        Trace(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
            //        throw new ApplicationException(string.Format("Exception {0} occurred, but transaction has an unexpected PromoterType of {1}", ex.ToString(), TxPromoterType(tx)));
            //    }
            //}
        }
NonMsdtcPromoterTests