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]); }
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]); }
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]); }
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); }
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); }
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); }
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); }
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); } }