public void ExportInterfaceWithTypeOf1()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForType <CFoo>().Export <IFoo>();
            var catalog = new TypeCatalog(new[] { typeof(CFoo) }, ctx);

            Assert.True(catalog.Parts.Count() != 0);

            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
            var importer  = new FooImporter();

            container.SatisfyImportsOnce(importer);

            Assert.True(importer.fooImporter != null, "fooImporter not set!");
        }
        public void ExportInheritedInterfaceWithImplements2()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForTypesDerivedFrom(typeof(IFoo)).Export((c) => c.Inherited().AsContractType(typeof(IFoo)));
            var catalog = new TypeCatalog(new[] { typeof(CFoo) }, ctx);

            Assert.True(catalog.Parts.Count() != 0);

            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
            var importer  = new FooImporter();

            container.SatisfyImportsOnce(importer);

            Assert.True(importer.fooImporter != null, "fooImporter not set!");
        }
示例#3
0
        public void ExportInheritedInterfaceWithImplements1()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForTypesDerivedFrom <IFoo>().Export((c) => c.Inherited().AsContractType(typeof(IFoo)));
            var catalog = new TypeCatalog(Helpers.GetEnumerableOfTypes(typeof(CFoo)), ctx);

            Assert.IsTrue(catalog.Parts.Count() != 0);

            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
            var importer  = new FooImporter();

            container.SatisfyImportsOnce(importer);

            Assert.IsNotNull(importer.fooImporter, "fooImporter not set!");
        }
示例#4
0
        public void SimpleComposition_ShouldSuceed()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForType <CFoo>().Export <IFoo>();
            var catalog = new TypeCatalog(Helpers.GetEnumerableOfTypes(typeof(CFoo)), ctx);

            Assert.IsTrue(catalog.Parts.Count() != 0);

            var compositionService = catalog.CreateCompositionService();

            var importer = new FooImporter();

            compositionService.SatisfyImportsOnce(importer);

            Assert.IsNotNull(importer.fooImporter, "FooImporter not set!");

            Assert.IsNotNull(importer.CompositionService, "CompositionService not set!");
        }