Beispiel #1
0
        public void PreviewImports_ReleaseImports_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value");
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 21);

            engine.PreviewImports(importer, null);

            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.AddExport("Value", 22));

            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.RemoveExport("Value"));

            engine.ReleaseImports(importer, null);

            exportProvider.AddExport("Value", 22);
            exportProvider.RemoveExport("Value");

            GC.KeepAlive(importer);
        }
        public void GetExports_WhenDefinitionsAreResurrected_ShouldTraceInformation()
        {
            using (TraceContext context = new TraceContext(SourceLevels.Information))
            {
                var part1 = PartFactory.CreateImporterExporter("Export", "Import");
                var part2 = PartFactory.CreateImporterExporter("Export", "Import");

                var sourceProvider = ExportProviderFactory.CreateRecomposable();
                var provider       = CreateCatalogExportProvider(part1, part2);
                provider.SourceProvider = sourceProvider;

                EnumerableAssert.IsEmpty(provider.GetExports <object>("Export"));

                // Add the required export to the source provider 'resurrect' the part
                sourceProvider.AddExport("Import", "Value");

                provider.GetExports <object>("Export");

                Assert.AreEqual(4, context.TraceEvents.Count);  // 2 for rejection, 2 for resurrection
                Assert.AreEqual(context.TraceEvents[2].EventType, TraceEventType.Information);
                Assert.AreEqual(context.TraceEvents[3].EventType, TraceEventType.Information);
                Assert.AreEqual(context.TraceEvents[2].Id, TraceId.Rejection_DefinitionResurrected);
                Assert.AreEqual(context.TraceEvents[3].Id, TraceId.Rejection_DefinitionResurrected);
            }
        }
Beispiel #3
0
        async Task InitializeInstanceAsync()
        {
            ComposableCatalog catalog = ComposableCatalog.Create(StandardResolver)
                                        .WithCompositionService()
                                        .WithDesktopSupport();

            var assemblies = new HashSet <Assembly> ();

            ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/TypeService/PlatformMefHostServices");
            ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/TypeService/MefHostServices");
            ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/Composition");

            // spawn discovery tasks in parallel for each assembly
            var tasks = new List <Task <DiscoveredParts> > (assemblies.Count);

            foreach (var assembly in assemblies)
            {
                var task = Task.Run(() => Discovery.CreatePartsAsync(assembly));
                tasks.Add(task);
            }

            foreach (var task in tasks)
            {
                catalog = catalog.AddParts(await task);
            }

            var discoveryErrors = catalog.DiscoveredParts.DiscoveryErrors;

            if (!discoveryErrors.IsEmpty)
            {
                foreach (var error in discoveryErrors)
                {
                    LoggingService.LogInfo("MEF discovery error", error);
                }

                // throw new ApplicationException ("MEF discovery errors");
            }

            CompositionConfiguration configuration = CompositionConfiguration.Create(catalog);

            if (!configuration.CompositionErrors.IsEmpty)
            {
                // capture the errors in an array for easier debugging
                var errors = configuration.CompositionErrors.SelectMany(e => e).ToArray();
                foreach (var error in errors)
                {
                    LoggingService.LogInfo("MEF composition error: " + error.Message);
                }

                // For now while we're still transitioning to VSMEF it's useful to work
                // even if the composition has some errors. TODO: re-enable this.
                //configuration.ThrowOnErrors ();
            }

            RuntimeComposition    = RuntimeComposition.CreateRuntimeComposition(configuration);
            ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
            ExportProvider        = ExportProviderFactory.CreateExportProvider();
            HostServices          = MefV1HostServices.Create(ExportProvider.AsExportProvider());
            ExportProviderV1      = NetFxAdapters.AsExportProvider(ExportProvider);
        }
Beispiel #4
0
        public void SatisfyImports_OneRecomposable_OneNotRecomposable()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import1  = ImportDefinitionFactory.Create("Value", true);
            var import2  = ImportDefinitionFactory.Create("Value", false);
            var importer = PartFactory.CreateImporter(import1, import2);

            exportProvider.AddExport("Value", 21);

            engine.SatisfyImports(importer);

            // Initial compose values should be 21
            Assert.Equal(21, importer.GetImport(import1));
            Assert.Equal(21, importer.GetImport(import2));

            // Reset value to ensure it doesn't get set to same value again
            importer.ResetImport(import1);
            importer.ResetImport(import2);

            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.ReplaceExportValue("Value", 42));

            Assert.Equal(null, importer.GetImport(import1));
            Assert.Equal(null, importer.GetImport(import2));

            GC.KeepAlive(importer);
        }
Beispiel #5
0
        public void SatisfyImports_TwoRecomposables_SingleExportValueChanged()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import1  = ImportDefinitionFactory.Create("Value1", true);
            var import2  = ImportDefinitionFactory.Create("Value2", true);
            var importer = PartFactory.CreateImporter(import1, import2);

            exportProvider.AddExport("Value1", 21);
            exportProvider.AddExport("Value2", 23);

            engine.SatisfyImports(importer);

            Assert.Equal(21, importer.GetImport(import1));
            Assert.Equal(23, importer.GetImport(import2));

            importer.ResetImport(import1);
            importer.ResetImport(import2);

            // Only change Value1
            exportProvider.ReplaceExportValue("Value1", 42);

            Assert.Equal(42, importer.GetImport(import1));

            Assert.Equal(null, importer.GetImport(import2));

            GC.KeepAlive(importer);
        }
Beispiel #6
0
        async Task InitializeInstanceAsync()
        {
            var assemblies = ReadAssembliesFromAddins();
            var caching    = new Caching(assemblies);

            // Try to use cached MEF data
            if (cacheEnabled && caching.CanUse())
            {
                RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching);
            }

            // Otherwise fallback to runtime discovery.
            if (RuntimeComposition == null)
            {
                RuntimeComposition = await CreateRuntimeCompositionFromDiscovery(caching);

                CachedComposition cacheManager = new CachedComposition();
                caching.Write(RuntimeComposition, cacheManager).Ignore();
            }

            ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
            ExportProvider        = ExportProviderFactory.CreateExportProvider();
            HostServices          = MefV1HostServices.Create(ExportProvider.AsExportProvider());
            ExportProviderV1      = NetFxAdapters.AsExportProvider(ExportProvider);
        }
Beispiel #7
0
        public void SatisfyImports_Recomposable_Unregister_ValueShouldChangeOnce()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            exportProvider.AddExport("Value", 21);

            var import   = ImportDefinitionFactory.Create("Value", true);
            var importer = PartFactory.CreateImporter(import);

            engine.SatisfyImports(importer);

            Assert.Equal(21, importer.GetImport(import));

            exportProvider.ReplaceExportValue("Value", 42);

            Assert.Equal(42, importer.GetImport(import));

            engine.ReleaseImports(importer, null);

            exportProvider.ReplaceExportValue("Value", 666);

            Assert.Equal(42, importer.GetImport(import));

            GC.KeepAlive(importer);
        }
        public void GetExports_AfterResurrectedDefinitionHasBeenRemovedAndReaddedToCatalog_ShouldNotBeTreatedAsRejected()
        {
            var definition1 = PartDefinitionFactory.Create(PartFactory.CreateImporterExporter("Export", "Import"));
            var definition2 = PartDefinitionFactory.Create(PartFactory.CreateImporterExporter("Export", "Import"));
            var catalog     = CatalogFactory.CreateMutable(definition1, definition2);

            var provider       = CreateCatalogExportProvider(catalog);
            var sourceProvider = ExportProviderFactory.CreateRecomposable();

            provider.SourceProvider = sourceProvider;

            var exports = provider.GetExports <object>("Export");

            EnumerableAssert.IsEmpty(exports, "definition1 and definition2 should have been rejected.");

            // Resurrect both definitions
            sourceProvider.AddExport("Import", new object());

            exports = provider.GetExports <object>("Export");

            Assert.AreEqual(2, exports.Count(), "definition1 and definition2 should have been resurrected.");

            catalog.RemoveDefinition(definition1);

            exports = provider.GetExports <object>("Export");
            Assert.AreEqual(1, exports.Count(), "definition1 should have been removed.");

            catalog.AddDefinition(definition1);

            exports = provider.GetExports <object>("Export");

            Assert.AreEqual(2, exports.Count(), "definition1 and definition2 should be both present.");
        }
Beispiel #9
0
        public void Constructor2_ArrayAsProvidersArgument_ShouldNotAllowModificationAfterConstruction()
        {
            var providers = new ExportProvider[] { ExportProviderFactory.Create() };
            var provider  = new AggregateExportProvider((IEnumerable <ExportProvider>)providers);

            providers[0] = null;

            Assert.IsNotNull(provider.Providers[0]);
        }
        public static ExtractInterfaceTestState Create(string markup, string languageName, CompilationOptions compilationOptions)
        {
            var exportProvider = ExportProviderFactory.CreateExportProvider();
            var workspace      = languageName == LanguageNames.CSharp
                ? TestWorkspace.CreateCSharp(markup, exportProvider: exportProvider, compilationOptions: compilationOptions as CSharpCompilationOptions)
                : TestWorkspace.CreateVisualBasic(markup, exportProvider: exportProvider, compilationOptions: compilationOptions);

            return(new ExtractInterfaceTestState(workspace));
        }
Beispiel #11
0
        public void GetExports2_NullAsDefinitionArgument_ShouldThrowArgumentNull()
        {
            var provider = ExportProviderFactory.Create();

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                provider.GetExports((ImportDefinition)null);
            });
        }
Beispiel #12
0
        public void TryGetExports_NullAsDefinitionArgument_ShouldThrowArgumentNull()
        {
            var provider = ExportProviderFactory.Create();

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                IEnumerable <Export> exports;
                provider.TryGetExports((ImportDefinition)null, null, out exports);
            });
        }
Beispiel #13
0
        public void PreviewImports_ZeroCollectionImport_ShouldSucceed()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", ImportCardinality.ZeroOrMore);
            var importer = PartFactory.CreateImporter(import);

            engine.PreviewImports(importer, null);

            GC.KeepAlive(importer);
        }
Beispiel #14
0
        public void TryGetExports_NullAsDefinitionArgument_ShouldNotSetExportsArgument()
        {
            var provider = ExportProviderFactory.Create();

            IEnumerable <Export> exports = new Export[0];
            IEnumerable <Export> results = exports;

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                provider.TryGetExports((ImportDefinition)null, null, out results);
            });

            Assert.AreSame(exports, results);
        }
        async Task InitializeInstanceAsync()
        {
            var timings  = new Dictionary <string, long> ();
            var metadata = new CompositionLoadMetadata(timings);

            using (var timer = Counters.CompositionLoad.BeginTiming(metadata)) {
                var fullTimer = System.Diagnostics.Stopwatch.StartNew();
                var stepTimer = System.Diagnostics.Stopwatch.StartNew();

                var mefAssemblies = ReadAssembliesFromAddins(timer);
                timings ["ReadFromAddins"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                var caching = new Caching(mefAssemblies);

                // Try to use cached MEF data

                var canUse = metadata.ValidCache = caching.CanUse();
                if (canUse)
                {
                    LoggingService.LogInfo("Creating MEF composition from cache");
                    RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching);
                }
                timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                // Otherwise fallback to runtime discovery.
                if (RuntimeComposition == null)
                {
                    LoggingService.LogInfo("Creating MEF composition from runtime");
                    var(runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery(caching, timer);

                    RuntimeComposition = runtimeComposition;

                    CachedComposition cacheManager = new CachedComposition();
                    caching.Write(RuntimeComposition, catalog, cacheManager).Ignore();
                }
                timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
                ExportProvider        = ExportProviderFactory.CreateExportProvider();
                HostServices          = MefV1HostServices.Create(ExportProvider.AsExportProvider());
                ExportProviderV1      = NetFxAdapters.AsExportProvider(ExportProvider);

                timings ["CreateServices"] = stepTimer.ElapsedMilliseconds;
                metadata.Duration          = fullTimer.ElapsedMilliseconds;
            }
        }
Beispiel #16
0
        public void PreviewImports_ZeroCollectionImport_NonRecomposable_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", ImportCardinality.ZeroOrMore, false, false);
            var importer = PartFactory.CreateImporter(import);

            engine.PreviewImports(importer, null);

            exportProvider.AddExport("Value", 21);
            exportProvider.AddExport("Value", 22);
            exportProvider.RemoveExport("Value");

            GC.KeepAlive(importer);
        }
Beispiel #17
0
        public void SatisfyImportsOnce_Unsuccessful_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value");
            var importer = PartFactory.CreateImporter(import);

            Assert.Throws <CompositionException>(() =>
                                                 engine.SatisfyImportsOnce(importer));

            exportProvider.AddExport("Value", 22);
            exportProvider.AddExport("Value", 23);
            exportProvider.RemoveExport("Value");

            GC.KeepAlive(importer);
        }
Beispiel #18
0
        public void SatisfyImports_MissingOptionalImport_Recomposable_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", ImportCardinality.ZeroOrOne, true, false);
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 20);

            engine.SatisfyImports(importer);

            exportProvider.AddExport("Value", 21);
            exportProvider.RemoveExport("Value");

            GC.KeepAlive(importer);
        }
        public void GetExports_WhenDefinitionIsRejected_ShouldTraceWarning()
        {
            using (TraceContext context = new TraceContext(SourceLevels.Warning))
            {
                var part     = PartFactory.CreateImporterExporter("Export", "Import");
                var provider = CreateCatalogExportProvider(part);
                provider.SourceProvider = ExportProviderFactory.CreateRecomposable();

                ExceptionAssert.Throws <ImportCardinalityMismatchException>(() =>
                {
                    provider.GetExport <object>("Export");
                });

                Assert.IsNotNull(context.LastTraceEvent);
                Assert.AreEqual(context.LastTraceEvent.EventType, TraceEventType.Warning);
                Assert.AreEqual(context.LastTraceEvent.Id, TraceId.Rejection_DefinitionRejected);
            }
        }
        public void SatisfyImports_Recomposable_Prerequisite_ValueShouldChange()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", true, true);
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 21);

            engine.SatisfyImports(importer);

            Assert.AreEqual(21, importer.GetImport(import));

            exportProvider.ReplaceExportValue("Value", 42);

            Assert.AreEqual(42, importer.GetImport(import), "Value should change!");

            GC.KeepAlive(importer);
        }
Beispiel #21
0
        public void SatisifyImportsOnce_Recomposable_ValueShouldNotChange_NoRecompositionRequested_ViaNonArgumentSignature()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            exportProvider.AddExport("Value", 21);

            var import   = ImportDefinitionFactory.Create("Value", true);
            var importer = PartFactory.CreateImporter(import);

            engine.SatisfyImportsOnce(importer);

            Assert.Equal(21, importer.GetImport(import));

            exportProvider.ReplaceExportValue("Value", 42);

            Assert.Equal(21, importer.GetImport(import));

            GC.KeepAlive(importer);
        }
Beispiel #22
0
        public void GetExports_WhenRejectedDefinitionRequiredImportIsAdded_ShouldBeResurrected()
        {
            var part = PartFactory.CreateImporterExporter("Export", "Import");

            var provider       = CreateCatalogExportProvider(part);
            var sourceProvider = ExportProviderFactory.CreateRecomposable();

            provider.SourceProvider = sourceProvider;

            var exports = provider.GetExports <object>("Export");

            Assert.Empty(exports);

            // Resurrect the definition
            sourceProvider.AddExport("Import", new object());

            exports = provider.GetExports <object>("Export");

            Assert.Equal(1, exports.Count());
        }
Beispiel #23
0
        public void SatisfyImports_ZeroCollectionImport_NonRecomposable_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", ImportCardinality.ZeroOrMore, false, false);
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 20);

            engine.SatisfyImports(importer);

            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.AddExport("Value", 21));

            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.RemoveExport("Value"));

            GC.KeepAlive(importer);
        }
Beispiel #24
0
        public void PreviewImports_Unsuccessful_AtomicComposition_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value");
            var importer = PartFactory.CreateImporter(import);

            using (var atomicComposition = new AtomicComposition())
            {
                Assert.Throws <ChangeRejectedException>(() =>
                                                        engine.PreviewImports(importer, atomicComposition));
            }

            exportProvider.AddExport("Value", 22);
            exportProvider.AddExport("Value", 23);
            exportProvider.RemoveExport("Value");

            GC.KeepAlive(importer);
        }
Beispiel #25
0
        async Task InitializeInstanceAsync(ITimeTracker <CompositionLoadMetadata> timer, HashSet <Assembly> mefAssemblies)
        {
            var metadata  = timer.Metadata;
            var fullTimer = System.Diagnostics.Stopwatch.StartNew();
            var stepTimer = System.Diagnostics.Stopwatch.StartNew();

            var caching = new Caching(mefAssemblies, new IdeRuntimeCompositionExceptionHandler());

            // Try to use cached MEF data
            using (timer) {
                var canUse = metadata.ValidCache = caching.CanUse();
                if (canUse)
                {
                    LoggingService.LogInfo("Creating MEF composition from cache");
                    RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching);
                }
                metadata.Timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                // Otherwise fallback to runtime discovery.
                if (RuntimeComposition == null)
                {
                    LoggingService.LogInfo("Creating MEF composition from runtime");
                    var(runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery(caching, timer);

                    RuntimeComposition = runtimeComposition;

                    CachedComposition cacheManager = new CachedComposition();
                    caching.Write(RuntimeComposition, catalog, cacheManager).Ignore();
                }
                metadata.Timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
                ExportProvider        = ExportProviderFactory.CreateExportProvider();
                HostServices          = Microsoft.VisualStudio.LanguageServices.VisualStudioMefHostServices.Create(ExportProvider);

                metadata.Timings ["CreateServices"] = stepTimer.ElapsedMilliseconds;
                metadata.Duration = fullTimer.ElapsedMilliseconds;
            }
        }
        public void GetExports_WhenMultipleRejectedDefinitionsRequiredImportsAreAdded_ShouldBeResurrected()
        {
            var part1 = PartFactory.CreateImporterExporter("Export", "Import");
            var part2 = PartFactory.CreateImporterExporter("Export", "Import");

            var provider       = CreateCatalogExportProvider(part1, part2);
            var sourceProvider = ExportProviderFactory.CreateRecomposable();

            provider.SourceProvider = sourceProvider;

            var exports = provider.GetExports <object>("Export");

            EnumerableAssert.IsEmpty(exports, "definition1 and definition2 should have been rejected.");

            // Resurrect both definitions
            sourceProvider.AddExport("Import", new object());

            exports = provider.GetExports <object>("Export");

            Assert.AreEqual(2, exports.Count(), "definition1 and definition2 should have been resurrected.");
        }
Beispiel #27
0
        public void SatisfyImports_NonRecomposable_Prerequisite_ValueShouldNotChange()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", false, true);
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 21);

            engine.SatisfyImports(importer);

            Assert.Equal(21, importer.GetImport(import));

            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.ReplaceExportValue("Value", 42));

            Assert.Equal(21, importer.GetImport(import));

            GC.KeepAlive(importer);
        }
Beispiel #28
0
        public void PreviewImports_Successful_AtomicComposition_RolledBack_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value");
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 21);

            using (var atomicComposition = new AtomicComposition())
            {
                engine.PreviewImports(importer, atomicComposition);

                // Let atomicComposition get disposed thus rolledback
            }

            exportProvider.AddExport("Value", 22);
            exportProvider.RemoveExport("Value");

            GC.KeepAlive(importer);
        }
Beispiel #29
0
        public void SatisfyImports_NonRecomposable_ValueShouldNotChange()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            exportProvider.AddExport("Value", 21);

            var import   = ImportDefinitionFactory.Create("Value", false);
            var importer = PartFactory.CreateImporter(import);

            engine.SatisfyImports(importer);

            Assert.Equal(21, importer.GetImport(import));

            // After rejection batch failures throw ChangeRejectedException to indicate that
            // the failure did not affect the container
            Assert.Throws <ChangeRejectedException>(() =>
                                                    exportProvider.ReplaceExportValue("Value", 42));

            Assert.Equal(21, importer.GetImport(import));

            GC.KeepAlive(importer);
        }
        public void GetExports_WhenDefinitionIsResurrected_ShouldTraceInformation()
        {
            using (TraceContext context = new TraceContext(SourceLevels.Information))
            {
                var part           = PartFactory.CreateImporterExporter("Export", "Import");
                var sourceProvider = ExportProviderFactory.CreateRecomposable();
                var provider       = CreateCatalogExportProvider(part);
                provider.SourceProvider = sourceProvider;

                ExceptionAssert.Throws <ImportCardinalityMismatchException>(() =>
                {
                    provider.GetExport <object>("Export");
                });

                // Add the required export to the source provider 'resurrect' the part
                sourceProvider.AddExport("Import", "Value");

                provider.GetExport <object>("Export");

                Assert.IsNotNull(context.LastTraceEvent);
                Assert.AreEqual(context.LastTraceEvent.EventType, TraceEventType.Information);
                Assert.AreEqual(context.LastTraceEvent.Id, TraceId.Rejection_DefinitionResurrected);
            }
        }