Exemple #1
0
        public void AllComposers()
        {
            var typeLoader = new TypeLoader(AppCaches.Disabled.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), Mock.Of <IProfilingLogger>());

            var register    = MockRegister();
            var composition = new Composition(register, typeLoader, Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Run));

            var types        = typeLoader.GetTypes <IComposer>().Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web"));
            var composers    = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());
            var requirements = composers.GetRequirements();
            var report       = Composers.GetComposersReport(requirements);

            Console.WriteLine(report);
            var composerTypes = composers.SortComposers(requirements);

            foreach (var type in composerTypes)
            {
                Console.WriteLine(type);
            }
        }
Exemple #2
0
        public void WeakDependencies()
        {
            var register    = MockRegister();
            var typeLoader  = MockTypeLoader();
            var composition = new Composition(register, typeLoader, Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types     = new[] { typeof(Composer10) };
            var composers = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());

            Composed.Clear();
            composers.Compose();
            Assert.AreEqual(1, Composed.Count);
            Assert.AreEqual(typeof(Composer10), Composed[0]);

            types     = new[] { typeof(Composer11) };
            composers = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());
            Composed.Clear();
            Assert.Throws <Exception>(() => composers.Compose());
            Console.WriteLine("throws:");
            composers = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());
            var requirements = composers.GetRequirements(false);

            Console.WriteLine(Composers.GetComposersReport(requirements));

            types     = new[] { typeof(Composer2) };
            composers = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());
            Composed.Clear();
            Assert.Throws <Exception>(() => composers.Compose());
            Console.WriteLine("throws:");
            composers    = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());
            requirements = composers.GetRequirements(false);
            Console.WriteLine(Composers.GetComposersReport(requirements));

            types     = new[] { typeof(Composer12) };
            composers = new Composers(composition, types, Enumerable.Empty <Attribute>(), Mock.Of <IProfilingLogger>());
            Composed.Clear();
            composers.Compose();
            Assert.AreEqual(1, Composed.Count);
            Assert.AreEqual(typeof(Composer12), Composed[0]);
        }