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 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); }
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); }
public void PreviewImports_Unsuccessful_NoAtomicComposition_ShouldNotBlockChanges() { var exportProvider = ExportProviderFactory.CreateRecomposable(); var engine = new ImportEngine(exportProvider); var import = ImportDefinitionFactory.Create("Value"); var importer = PartFactory.CreateImporter(import); Assert.Throws <CompositionException>(() => engine.PreviewImports(importer, null)); exportProvider.AddExport("Value", 22); exportProvider.AddExport("Value", 23); exportProvider.RemoveExport("Value"); GC.KeepAlive(importer); }
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); }
public void PreviewImports_Successful_AtomicComposition_Completeted_ShouldBlockChanges() { 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); atomicComposition.Complete(); } Assert.Throws <ChangeRejectedException>(() => exportProvider.AddExport("Value", 22)); Assert.Throws <ChangeRejectedException>(() => exportProvider.RemoveExport("Value")); GC.KeepAlive(importer); }