示例#1
0
        public void WeakDependencies()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = new[] { typeof(Composer10) };
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

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

            types      = new[] { typeof(Composer11) };
            components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());
            Composed.Clear();
            Assert.Throws <Exception>(() => components.Compose());

            types      = new[] { typeof(Composer2) };
            components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());
            Composed.Clear();
            Assert.Throws <Exception>(() => components.Compose());

            types      = new[] { typeof(Composer12) };
            components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());
            Composed.Clear();
            components.Compose();
            Assert.AreEqual(1, Composed.Count);
            Assert.AreEqual(typeof(Composer12), Composed[0]);
        }
示例#2
0
        public void DisableMissing()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            components.Compose();
            Assert.AreEqual(2, Composed.Count);
            Assert.AreEqual(typeof(Composer6), Composed[0]);
            Assert.AreEqual(typeof(Composer8), Composed[1]);
        }
示例#3
0
        public void Requires1()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) };
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            components.Compose();
            Assert.AreEqual(2, Composed.Count);
            Assert.AreEqual(typeof(Composer6), Composed[0]);
            Assert.AreEqual(typeof(Composer8), Composed[1]);
        }
示例#4
0
        public void Boot2()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = TypeArray <Composer20, Composer21>();
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            // 21 is required by 20
            // => reorder components accordingly
            components.Compose();
            AssertTypeArray(TypeArray <Composer21, Composer20>(), Composed);
        }
示例#5
0
        public void Boot1B()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Run));

            var types      = TypeArray <Composer1, Composer2, Composer3, Composer4>();
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            // 2 is Core and requires 4
            // 3 is User - stays with RuntimeLevel.Run
            // => reorder components accordingly
            components.Compose();
            AssertTypeArray(TypeArray <Composer1, Composer4, Composer2, Composer3>(), Composed);
        }
示例#6
0
        public void BrokenRequired()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = TypeArray <Composer2, Composer4, Composer13>();
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            // 2 is Core and requires 4
            // 13 is required by 1
            // 1 is missing
            // => reorder components accordingly
            components.Compose();
            AssertTypeArray(TypeArray <Composer4, Composer2, Composer13>(), Composed);
        }
示例#7
0
        public void Boot3()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = TypeArray <Composer22, Composer24, Composer25>();
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            // i23 requires 22
            // 24, 25 implement i23
            // 25 required by i23
            // => reorder components accordingly
            components.Compose();
            AssertTypeArray(TypeArray <Composer22, Composer25, Composer24>(), Composed);
        }
示例#8
0
        public void BrokenRequire()
        {
            var register    = MockRegister();
            var composition = new Composition(register, MockTypeLoader(), Mock.Of <IProfilingLogger>(), MockRuntimeState(RuntimeLevel.Unknown));

            var types      = TypeArray <Composer1, Composer2, Composer3>();
            var components = new Core.Components.Composers(composition, types, Mock.Of <IProfilingLogger>());

            Composed.Clear();
            try
            {
                // 2 is Core and requires 4
                // 4 is missing
                // => throw
                components.Compose();
                Assert.Fail("Expected exception.");
            }
            catch (Exception e)
            {
                Assert.AreEqual("Broken composer dependency: Umbraco.Tests.Components.ComponentTests+Composer2 -> Umbraco.Tests.Components.ComponentTests+Composer4.", e.Message);
            }
        }