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 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); }