Пример #1
0
        public void ImplementsIFooWithExport_ShouldFindTwoParts()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForTypesDerivedFrom <IFoo>().Export();
            var catalog = new TypeCatalog(Helpers.GetEnumerableOfTypes(typeof(IFoo), typeof(FooImplementation1), typeof(FooImplementation2)), ctx);

            Assert.IsTrue(catalog.Parts.Count() == 2);
        }
Пример #2
0
        public void ExportInheritedInterfaceWithImplements2()
        {
            var ctx = new RegistrationBuilder();

            ctx.ForTypesDerivedFrom(typeof(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!");
        }