private static void DisposeAndVerify(ActivityEnrichmentScopeBase enrichmentScope) { enrichmentScope.Dispose(); if (enrichmentScope is ActionActivityEnrichmentScope actionActivityEnrichmentScope) { Assert.IsNull(actionActivityEnrichmentScope.EnrichmentAction); } else if (enrichmentScope is GenericActivityEnrichmentScope <string> genericActivityEnrichmentScope) { Assert.IsNull(genericActivityEnrichmentScope.ActivityEnricher); } else { throw new NotSupportedException(); } Assert.IsNull(enrichmentScope.Parent); Assert.IsNull(enrichmentScope.Child); }
public void DisposeOutOfOrderTest3() { using ActivityEnrichmentScopeBase scope1 = (ActivityEnrichmentScopeBase)ActivityEnrichmentScope.Begin(s_EnrichmentAction); using ActivityEnrichmentScopeBase scope2 = (ActivityEnrichmentScopeBase)ActivityEnrichmentScope.Begin(s_EnrichmentAction); using ActivityEnrichmentScopeBase scope3 = (ActivityEnrichmentScopeBase)ActivityEnrichmentScope.Begin(s_EnrichmentAction); /* Close order: 1, 2, 3 */ Assert.IsNotNull(scope1); Assert.IsNotNull(scope2); Assert.IsNotNull(scope3); Assert.IsNull(scope1.Parent); Assert.AreEqual(scope1.Child, scope2); Assert.AreEqual(scope2.Parent, scope1); Assert.AreEqual(scope2.Child, scope3); Assert.AreEqual(scope3.Parent, scope2); Assert.IsNull(scope3.Child); Assert.AreEqual(scope3, ActivityEnrichmentScopeBase.Current); DisposeAndVerify(scope1); Assert.IsNull(scope2.Parent); Assert.AreEqual(scope2.Child, scope3); Assert.AreEqual(scope3.Parent, scope2); Assert.IsNull(scope3.Child); Assert.AreEqual(scope3, ActivityEnrichmentScopeBase.Current); DisposeAndVerify(scope2); Assert.IsNull(scope3.Parent); Assert.IsNull(scope3.Child); Assert.AreEqual(scope3, ActivityEnrichmentScopeBase.Current); DisposeAndVerify(scope3); Assert.IsNull(ActivityEnrichmentScopeBase.Current); }