diff --git a/src/libraries/System.Transactions.Local/tests/NonMsdtcPromoterTests.cs b/src/libraries/System.Transactions.Local/tests/NonMsdtcPromoterTests.cs index dc2ba01f63bcbb..6313200e46ada0 100644 --- a/src/libraries/System.Transactions.Local/tests/NonMsdtcPromoterTests.cs +++ b/src/libraries/System.Transactions.Local/tests/NonMsdtcPromoterTests.cs @@ -21,7 +21,6 @@ public class NonMsdtcPromoterTests : IDisposable private static MethodInfo s_setDistributedTransactionIdentifierMethodInfo; private static MethodInfo s_getPromotedTokenMethodInfo; private static PropertyInfo s_promoterTypePropertyInfo; - private static FieldInfo s_promoterTypeDtcFieldInfo; public NonMsdtcPromoterTests() { @@ -51,17 +50,12 @@ private static void VerifySoftDependencies() // And the PropertyInfo objects for PromoterType s_promoterTypePropertyInfo = typeof(Transaction).GetTypeInfo().GetProperty("PromoterType", typeof(Guid)); - - // And the FieldInfo for TransactionInterop.PromoterTypeDtc - s_promoterTypeDtcFieldInfo = typeof(TransactionInterop).GetTypeInfo().GetField("PromoterTypeDtc", BindingFlags.Public | BindingFlags.Static); } bool allMethodsAreThere = ((s_enlistPromotableSinglePhaseMethodInfo != null) && (s_setDistributedTransactionIdentifierMethodInfo != null) && (s_getPromotedTokenMethodInfo != null) && - (s_promoterTypePropertyInfo != null) && - (s_promoterTypeDtcFieldInfo != null) - ); + (s_promoterTypePropertyInfo != null)); Assert.True(allMethodsAreThere, "At least one of the expected new methods or properties is not implemented by the available System.Transactions."); } @@ -339,14 +333,6 @@ private static byte[] TxPromotedToken(Transaction txToGet) return (byte[])s_getPromotedTokenMethodInfo.Invoke(txToGet, null); } - private static Guid PromoterTypeDtc - { - get - { - return (Guid)s_promoterTypeDtcFieldInfo.GetValue(null); - } - } - #endregion #region NonMSDTCPromoterEnlistment @@ -1706,45 +1692,6 @@ private static void TestCase_PromoterType() TestPassed(); } - private static void TestCase_PromoterTypeMSDTC() - { - string testCaseDescription = "TestCase_PromoterTypeMSDTC"; - - Trace("**** " + testCaseDescription + " ****"); - - AutoResetEvent volCompleted = new AutoResetEvent(false); - MyEnlistment vol = null; - - try - { - using (TransactionScope ts = new TransactionScope()) - { - Assert.Equal(Guid.Empty, TxPromoterType(Transaction.Current)); - - vol = CreateVolatileEnlistment(volCompleted); - - // Force MSDTC promotion. - TransactionInterop.GetDtcTransaction(Transaction.Current); - - // TransactionInterop.PromoterTypeDtc - Assert.Equal(PromoterTypeDtc, TxPromoterType(Transaction.Current)); - - ts.Complete(); - } - } - catch (Exception ex) - { - Trace(string.Format("Caught unexpected exception {0}:{1}", ex.GetType().ToString(), ex.ToString())); - return; - } - - Assert.True(volCompleted.WaitOne(TimeSpan.FromSeconds(5))); - - Assert.True(vol.CommittedOutcome); - - TestPassed(); - } - private static void TestCase_FailPromotableSinglePhaseNotificationCalls() { string testCaseDescription = "TestCase_FailPromotableSinglePhaseNotificationCalls"; @@ -2133,16 +2080,6 @@ public void PSPENonMsdtcGetPromoterType() TestCase_PromoterType(); } - /// - /// PSPE Non-MSDTC Get PromoterType. - /// - [Fact] - public void PSPENonMsdtcGetPromoterTypeMSDTC() - { - // get_PromoterType - TestCase_PromoterTypeMSDTC(); - } - /// /// PSPE Non-MSDTC Fail PromotableSinglePhaseNotification Calls. /// diff --git a/src/libraries/System.Transactions.Local/tests/OleTxNonWindowsUnsupportedTests.cs b/src/libraries/System.Transactions.Local/tests/OleTxNonWindowsUnsupportedTests.cs index fc753cef0e2d0a..bcf50d06c31738 100644 --- a/src/libraries/System.Transactions.Local/tests/OleTxNonWindowsUnsupportedTests.cs +++ b/src/libraries/System.Transactions.Local/tests/OleTxNonWindowsUnsupportedTests.cs @@ -55,10 +55,15 @@ public void TransmitterPropagationToken() [Fact] public void GetWhereabouts() - => Assert.Throws(() => TransactionInterop.GetWhereabouts()); + => Assert.Throws(TransactionInterop.GetWhereabouts); [Fact] public void GetExportCookie() - => Assert.Throws(() => TransactionInterop.GetExportCookie( - new CommittableTransaction(), new byte[200])); + => Assert.Throws(() => + TransactionInterop.GetExportCookie(new CommittableTransaction(), new byte[200])); + + [Fact] + public void GetDtcTransaction() + => Assert.Throws(() => + TransactionInterop.GetDtcTransaction(new CommittableTransaction())); } diff --git a/src/libraries/System.Transactions.Local/tests/OleTxTests.cs b/src/libraries/System.Transactions.Local/tests/OleTxTests.cs index 6a97aed542a13f..e646c09a59326c 100644 --- a/src/libraries/System.Transactions.Local/tests/OleTxTests.cs +++ b/src/libraries/System.Transactions.Local/tests/OleTxTests.cs @@ -433,6 +433,34 @@ public void GetExportCookie() Assert.Equal(tx.TransactionInformation.DistributedIdentifier, tx2.TransactionInformation.DistributedIdentifier); }); + // Test currently skipped, #74745 + private void GetDtcTransaction() + => Test(() => + { + using var tx = new CommittableTransaction(); + + var outcomeReceived = new AutoResetEvent(false); + + var enlistment = new TestEnlistment( + Phase1Vote.Prepared, EnlistmentOutcome.Committed, outcomeReceived: outcomeReceived); + + Assert.Equal(Guid.Empty, tx.PromoterType); + + tx.EnlistVolatile(enlistment, EnlistmentOptions.None); + + // Forces promotion to MSDTC, returns an ITransaction for use only with System.EnterpriseServices. + _ = TransactionInterop.GetDtcTransaction(tx); + + Assert.Equal(TransactionStatus.Active, tx.TransactionInformation.Status); + Assert.Equal(TransactionInterop.PromoterTypeDtc, tx.PromoterType); + + tx.Commit(); + + Assert.True(outcomeReceived.WaitOne(Timeout)); + Assert.Equal(EnlistmentOutcome.Committed, enlistment.Outcome); + Retry(() => Assert.Equal(TransactionStatus.Committed, tx.TransactionInformation.Status)); + }); + private static void Test(Action action) { // Temporarily skip on 32-bit where we have an issue.