예제 #1
0
        public void StandardExportInterfacesDefaultContractShouldWork()
        {            //Same test as above only using default export builder
            var builder = new RegistrationBuilder();

            builder.ForTypesMatching((t) => true).ExportInterfaces((iface) => iface != typeof(System.IDisposable));
            builder.ForTypesMatching((t) => t.GetInterfaces().Where((iface) => iface != typeof(System.IDisposable)).Count() == 0).Export();

            var types   = new Type[] { typeof(Standard), typeof(Dippy), typeof(Derived), typeof(BareClass) };
            var catalog = new TypeCatalog(types, builder);

            var cs = catalog.CreateCompositionService();

            var importer = new Importer();

            cs.SatisfyImportsOnce(importer);

            Assert.IsNotNull(importer.First);
            Assert.IsTrue(importer.First.Count() == 3);
            Assert.IsNotNull(importer.Second);
            Assert.IsTrue(importer.Second.Count() == 3);
            Assert.IsNotNull(importer.Third);
            Assert.IsTrue(importer.Third.Count() == 3);
            Assert.IsNotNull(importer.Fourth);
            Assert.IsTrue(importer.Fourth.Count() == 3);
            Assert.IsNotNull(importer.Fifth);
            Assert.IsTrue(importer.Fifth.Count() == 3);

            Assert.IsNull(importer.Base);
            Assert.IsNull(importer.Derived);
            Assert.IsNull(importer.Dippy);
            Assert.IsNull(importer.Standard);
            Assert.IsNull(importer.Disposable);
            Assert.IsNotNull(importer.BareClass);
        }
        public void RegistrationBuilder_WithExportDelegatesShouldNotThrow()
        {
            var rb  = new RegistrationBuilder();
            var cat = new TypeCatalog(new Type[] { typeof(Class1), typeof(Factory) }, rb);

            CompositionService cs = cat.CreateCompositionService();
            var test = new Class1();

            cs.SatisfyImportsOnce(test);
        }
예제 #3
0
        public void CreateCompositionService_ImmutableCatalog_ShouldSucceed()
        {
            //Create and dispose an empty immutable catalog, I.e no INotifyComposablePartCatalogChanged interface
            var catalog = new TypeCatalog();

            using (var cs = catalog.CreateCompositionService())
            {
                //Do nothing
            }
        }
예제 #4
0
        public void InsideTheLambdaCallGetCustomAttributesShouldSucceed()
        {
            //Same test as above only using default export builder
            var builder = new RegistrationBuilder();

            builder.ForTypesMatching((t) => !t.IsDefined(typeof(MyDoNotIncludeAttribute), false)).Export();

            var types   = new Type[] { typeof(MyNotToBeIncludedClass), typeof(MyToBeIncludedClass) };
            var catalog = new TypeCatalog(types, builder);

            var cs       = catalog.CreateCompositionService();
            var importer = new ImporterOfMyNotTobeIncludedClass();

            cs.SatisfyImportsOnce(importer);

            Assert.IsNull(importer.MyNotToBeIncludedClass);
            Assert.IsNotNull(importer.MyToBeIncludedClass);
        }
예제 #5
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!");
        }
예제 #6
0
        public void ComposeAppInRootScope_ShouldSucceed()
        {
            var catalog = new TypeCatalog(typeof(Foo1), typeof(Child));

            var cs  = catalog.CreateCompositionService();
            var app = new App();

            cs.SatisfyImportsOnce(app);

            var e1 = app.FooFactory.CreateExport();
            var e2 = app.FooFactory.CreateExport();
            var e3 = app.FooFactory.CreateExport();

            e1.Value.FooChild.FooValue = 10;
            e2.Value.FooChild.FooValue = 20;
            e3.Value.FooChild.FooValue = 30;

            Assert.Equal <int>(30, e1.Value.FooChild.FooValue);
            Assert.Equal <int>(30, e2.Value.FooChild.FooValue);
            Assert.Equal <int>(30, e3.Value.FooChild.FooValue);
        }