[ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void ImportCompletedBindChildIndirectlyThroughParentContainerBind()
        {
            var cat    = CatalogFactory.CreateDefaultAttributed();
            var parent = new CompositionContainer(cat);

            CompositionBatch parentBatch = new CompositionBatch();
            CompositionBatch childBatch  = new CompositionBatch();

            parentBatch.AddExportedValue <ICompositionService>(parent);
            parent.Compose(parentBatch);
            var child = new CompositionContainer(parent);

            var parentImporter = new MyNotifyImportImporter(parent);
            var childImporter  = new MyNotifyImportImporter(child);

            parentBatch = new CompositionBatch();
            parentBatch.AddPart(parentImporter);
            childBatch.AddParts(childImporter, new MyNotifyImportExporter());

            parent.Compose(parentBatch);
            child.Compose(childBatch);

            Assert.Equal(1, parentImporter.ImportCompletedCallCount);
            Assert.Equal(1, childImporter.ImportCompletedCallCount);

            MyNotifyImportExporter parentExporter = parent.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter");

            Assert.Equal(1, parentExporter.ImportCompletedCallCount);

            MyNotifyImportExporter childExporter = child.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter");

            Assert.Equal(1, childExporter.ImportCompletedCallCount);
        }
        public void ImportCompletedUsingSatisfyImportsOnce()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint         = new UpperCaseStringComponent();
            var entrypointPart     = AttributedModelServices.CreatePart(entrypoint);

            batch.AddParts(new LowerCaseString("abc"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.Equal(1, entrypoint.LowerCaseStrings.Count);
            Assert.Equal(1, entrypoint.ImportCompletedCallCount);
            Assert.Equal(1, entrypoint.UpperCaseStrings.Count);
            Assert.Equal("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.Equal("ABC", entrypoint.UpperCaseStrings[0]);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.Equal(1, entrypoint.LowerCaseStrings.Count);
            Assert.Equal(1, entrypoint.ImportCompletedCallCount);
            Assert.Equal(1, entrypoint.UpperCaseStrings.Count);
            Assert.Equal("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.Equal("ABC", entrypoint.UpperCaseStrings[0]);

            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);
            container.SatisfyImportsOnce(entrypointPart);

            Assert.Equal(2, entrypoint.LowerCaseStrings.Count);
            Assert.Equal(2, entrypoint.ImportCompletedCallCount);
            Assert.Equal(2, entrypoint.UpperCaseStrings.Count);
            Assert.Equal("abc", entrypoint.LowerCaseStrings[0].Value.String);
            Assert.Equal("ABC", entrypoint.UpperCaseStrings[0]);
            Assert.Equal("def", entrypoint.LowerCaseStrings[1].Value.String);
            Assert.Equal("DEF", entrypoint.UpperCaseStrings[1]);
        }
        public void ImportCollectionsFromCatalogOnly()
        {
            var      cat       = CatalogFactory.CreateDefaultAttributed();
            var      container = new CompositionContainer(cat);
            Importer importer  = new Importer();

            CompositionBatch batch = new CompositionBatch();

            batch.AddParts(importer);
            container.Compose(batch);

            importer.VerifyImport(21, 42);
        }
        public void ImportCompletedAddPartAndBindComponent()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();

            batch.AddParts(new CallbackImportNotify(delegate
            {
                batch = new CompositionBatch();
                batch.AddPart(new object());
                container.Compose(batch);
            }));

            container.Compose(batch);
        }
        public void ImportCollectionsNameless()
        {
            // Verifing that the contract name gets the correct value
            var container               = ContainerFactory.Create();
            NamelessImporter importer   = new NamelessImporter();
            NamelessExporter exporter42 = new NamelessExporter(42);
            NamelessExporter exporter0  = new NamelessExporter(0);

            CompositionBatch batch = new CompositionBatch();

            batch.AddParts(importer, exporter42, exporter0);
            container.Compose(batch);

            EnumerableAssert.AreEqual(importer.ReadWriteIList, 42, 0);
        }
        public void ImportCollectionsFormContainerAndCatalog()
        {
            var      cat       = CatalogFactory.CreateDefaultAttributed();
            var      container = new CompositionContainer(cat);
            Importer importer  = new Importer();

            CompositionBatch batch = new CompositionBatch();

            batch.AddParts(importer
                           , new ExporterDefault21(22)
                           , new ExporterDefault42(43));

            container.Compose(batch);

            importer.VerifyImport(22, 43, 21, 42);
        }
        public void ImportCollectionsFromContainerOnly()
        {
            var      container = ContainerFactory.Create();
            Importer importer  = new Importer();

            CompositionBatch batch = new CompositionBatch();

            batch.AddParts(importer
                           , new ExporterDefault21()
                           , new ExporterDefault21(22)
                           , new ExporterDefault42()
                           , new ExporterDefault42(43));

            container.Compose(batch);

            importer.VerifyImport(21, 22, 42, 43);
        }
        public void ImportCompletedTest()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint         = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 1);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 1);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 1);
            Assert.Equal(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.Equal(entrypoint.UpperCaseStrings[0], "ABC");
        }
        public void DelayImportValueComComponent()
        {
            CTaskScheduler scheduler = new CTaskScheduler();

            try
            {
                var container = ContainerFactory.Create();
                var importer  = new DelayImportComComponent();

                CompositionBatch batch = new CompositionBatch();
                batch.AddParts(importer);
                batch.AddExportedValue <ITaskScheduler>("TaskScheduler", (ITaskScheduler)scheduler);

                container.Compose(batch);

                Assert.Equal <object>(scheduler, importer.TaskScheduler.Value);
            }
            finally
            {
                Marshal.ReleaseComObject(scheduler);
            }
        }
Beispiel #10
0
        [ActiveIssue(25498, TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void ImportCompletedChildDoesnotNeedParentContainer()
        {
            var cat    = CatalogFactory.CreateDefaultAttributed();
            var parent = new CompositionContainer(cat);

            CompositionBatch parentBatch = new CompositionBatch();
            CompositionBatch childBatch  = new CompositionBatch();

            parentBatch.AddExportedValue <ICompositionService>(parent);
            parent.Compose(parentBatch);

            var child = new CompositionContainer(parent);

            var parentImporter = new MyNotifyImportImporter(parent);
            var childImporter  = new MyNotifyImportImporter(child);

            parentBatch = new CompositionBatch();
            parentBatch.AddPart(parentImporter);

            childBatch.AddParts(childImporter, new MyNotifyImportExporter());

            child.Compose(childBatch);

            Assert.Equal(0, parentImporter.ImportCompletedCallCount);
            Assert.Equal(1, childImporter.ImportCompletedCallCount);

            // Parent will become bound at this point.
            MyNotifyImportExporter parentExporter = parent.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter");

            parent.Compose(parentBatch);
            Assert.Equal(1, parentImporter.ImportCompletedCallCount);
            Assert.Equal(1, parentExporter.ImportCompletedCallCount);

            MyNotifyImportExporter childExporter = child.GetExportedValue <MyNotifyImportExporter>("MyNotifyImportExporter");

            Assert.Equal(1, childExporter.ImportCompletedCallCount);
        }
Beispiel #11
0
        public void ImportCompletedCalledAfterAllImportsAreFullyComposed()
        {
            int importSatisfationCount = 0;
            var importer1 = new MyEventDrivenFullComposedNotifyImporter1();
            var importer2 = new MyEventDrivenFullComposedNotifyImporter2();

            Action <object, EventArgs> verificationAction = (object sender, EventArgs e) =>
            {
                Assert.True(importer1.AreAllImportsFullyComposed);
                Assert.True(importer2.AreAllImportsFullyComposed);
                ++importSatisfationCount;
            };

            importer1.ImportsSatisfied += new EventHandler(verificationAction);
            importer2.ImportsSatisfied += new EventHandler(verificationAction);

            // importer1 added first
            var batch = new CompositionBatch();

            batch.AddParts(importer1, importer2);

            var container = ContainerFactory.Create();

            container.ComposeExportedValue <ICompositionService>(container);
            container.Compose(batch);
            Assert.Equal(2, importSatisfationCount);

            // importer2 added first
            importSatisfationCount = 0;
            batch = new CompositionBatch();
            batch.AddParts(importer2, importer1);

            container = ContainerFactory.Create();
            container.ComposeExportedValue <ICompositionService>(container);
            container.Compose(batch);
            Assert.Equal(2, importSatisfationCount);
        }
Beispiel #12
0
        public void ImportCompletedWithRecomposing()
        {
            var container          = ContainerFactory.Create();
            CompositionBatch batch = new CompositionBatch();
            var entrypoint         = new UpperCaseStringComponent();

            batch.AddParts(new LowerCaseString("abc"), entrypoint);
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 1);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 1);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 1);
            Assert.Equal(entrypoint.LowerCaseStrings[0].Value.String, "abc");
            Assert.Equal(entrypoint.UpperCaseStrings[0], "ABC");

            // Add another component to verify recomposing
            batch = new CompositionBatch();
            batch.AddParts(new LowerCaseString("def"));
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 2);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 2);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 2);
            Assert.Equal(entrypoint.LowerCaseStrings[1].Value.String, "def");
            Assert.Equal(entrypoint.UpperCaseStrings[1], "DEF");

            // Verify that adding a random component doesn't cause
            // the OnImportsSatisfied to be called again.
            batch = new CompositionBatch();
            batch.AddParts(new object());
            container.Compose(batch);

            Assert.Equal(entrypoint.LowerCaseStrings.Count, 2);
            Assert.Equal(entrypoint.ImportCompletedCallCount, 2);
            Assert.Equal(entrypoint.UpperCaseStrings.Count, 2);
        }