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

Enlist() публичный Метод

public Enlist ( Transaction txToEnlist = null, bool expectRejection = false, bool comparePromotedToken = false ) : bool
txToEnlist Transaction
expectRejection bool
comparePromotedToken bool
Результат bool
            public bool Enlist(Transaction txToEnlist = null, bool expectRejection = false, bool comparePromotedToken = false)
            {
                if (txToEnlist == null)
                {
                    txToEnlist = Transaction.Current;
                }

                // invoke txToEnlist.EnlistPromotableSinglePhase(this, this.promoterType) via reflection.
                if (!EnlistPromotable(this, txToEnlist, _promoterType))
                {
                    if (expectRejection)
                    {
                        // invoke txToEnlist.PromoterType and txToEnlist.PromotedToken via reflection
                        if (comparePromotedToken && (TxPromoterType(txToEnlist) == _promoterType))
                        {
                            if (TxPromotedToken(txToEnlist) != _promotedToken)
                            {
                                throw new ApplicationException("The PromotedToken does not match");
                            }
                        }
                        return false;
                    }
                    else
                    {
                        throw new ApplicationException("EnlistPromotableSinglePhase failed when expected to succeed");
                    }
                }
                else if (expectRejection)
                {
                    throw new ApplicationException("EnlistPromotableSinglePhase succeeded when expected to fail");
                }

                _enlistedTransaction = txToEnlist;
                return true;
            }