Example #1
0
        public override void Before(MethodInfo?methodUnderTest)
        {
#if false
            MefHostServices.TestAccessor.HookServiceCreation(CreateMefHostServices);

            // make sure we enable this for all unit tests
            AsynchronousOperationListenerProvider.Enable(enable: true, diagnostics: true);
#endif

            ExportProviderCache.SetEnabled_OnlyUseExportProviderAttributeCanCall(true);
        }
Example #2
0
        /// <summary>
        /// To the extent reasonably possible, this method resets the state of the test environment to the same state as
        /// it started, ensuring that tests running in sequence cannot influence the outcome of later tests.
        /// </summary>
        /// <remarks>
        /// <para>The test cleanup runs in two primary steps:</para>
        /// <list type="number">
        /// <item>Waiting for asynchronous operations started by the test to complete.</item>
        /// <item>Disposing of mutable resources created by the test.</item>
        /// <item>Clearing static state variables related to the use of MEF during a test.</item>
        /// </list>
        /// </remarks>
        public override void After(MethodInfo?methodUnderTest)
        {
            try
            {
                foreach (var exportProvider in ExportProviderCache.ExportProvidersForCleanup)
                {
                    DisposeExportProvider(exportProvider);
                }
            }
            finally
            {
#if false
                // Replace hooks with ones that always throw exceptions. These hooks detect cases where code executing
                // after the end of a test attempts to create an ExportProvider.
                MefHostServices.TestAccessor.HookServiceCreation(DenyMefHostServicesCreationBetweenTests);
#endif

                // Reset static state variables.
#if false
                _hostServices = null;
#endif
                ExportProviderCache.SetEnabled_OnlyUseExportProviderAttributeCanCall(false);
            }
        }