Exemplo n.º 1
0
        public void TargetName_should_TestExpectation()
        {
            var loader =
                new TypeLoader();
            loader.AddTypes(() => Assembly.GetExecutingAssembly().GetExportedTypes());

            var catalog =
                new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new ConventionCatalog(new[] { new MyRegistry() }, loader));

            var instance =
                new Host();

            var batch =
                new CompositionBatch();
            batch.AddPart(instance);

            var container =
                new CompositionContainer(catalog);

            container.Compose(batch);

            instance.Widgets.Count().ShouldEqual(2);
        }
Exemplo n.º 2
0
        public void Ctor_injection_test()
        {
            var loader =
                new TypeLoader();
            loader.AddTypes(() => Assembly.GetExecutingAssembly().GetExportedTypes());

            var catalog =
                new AggregateCatalog();

            catalog.Catalogs.Add(new ConventionCatalog(new[] { new CtorRegistry() }, loader));

            var instance =
                new ConventionPart<InjectedHost>();

            var batch =
                new CompositionBatch();
            batch.AddPart(instance);

            var container =
                new CompositionContainer(catalog);

            container.Compose(batch);

            instance.Imports[0].Widgets.Count().ShouldEqual(2);
        }
        private static ITypeLoader CreateDefaultTypeLoader()
        {
            var typeLoader =
                new TypeLoader();
            typeLoader.AddTypes(() => new[] { typeof(FakePart) });

            return typeLoader;
        }