Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void SatisfyImports_ZeroCollectionImport_Recomposable_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

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

            exportProvider.AddExport("Value", 20);

            engine.SatisfyImports(importer);

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

            GC.KeepAlive(importer);
        }
Ejemplo n.º 5
0
        public void SatisfyImports_MissingOptionalImport_NonRecomposable_ShouldNotBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine         = new ImportEngine(exportProvider);

            var import   = ImportDefinitionFactory.Create("Value", ImportCardinality.ZeroOrOne, 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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }