internal static void CheckChildren <T>(IStObjObjectEngineMap map, string childrenTypeNames) { IEnumerable <IStObjResult> items = map.ToHead(typeof(T)) !.Children; var s1 = items.Select(i => i.ClassType.Name).OrderBy(Util.FuncIdentity); var s2 = childrenTypeNames.Split(',').OrderBy(Util.FuncIdentity); if (!s1.SequenceEqual(s2)) { Assert.Fail("Expecting '{0}' but was '{1}'.", String.Join(", ", s2), String.Join(", ", s1)); } }
public void DoTest() { StObjCollector collector = new StObjCollector(TestHelper.Monitor, new SimpleServiceContainer(), configurator: new StObjPropertyConfigurator()); collector.RegisterType(typeof(BSpec)); collector.RegisterType(typeof(ASpec)); collector.DependencySorterHookInput = items => items.Trace(TestHelper.Monitor); collector.DependencySorterHookOutput = sortedItems => sortedItems.Trace(TestHelper.Monitor); var(r, map) = TestHelper.CompileAndLoadStObjMap(collector); // Check collector result. { Assert.That(r.HasFatalError, Is.False); Debug.Assert(r.EngineMap != null, "Since HasFatalError is false."); IStObjObjectEngineMap stObjs = r.EngineMap.StObjs; Assert.That(stObjs.Obtain <B>() !.TheA, Is.SameAs(stObjs.Obtain <A>()).And.SameAs(stObjs.Obtain <ASpec>())); Assert.That(stObjs.Obtain <ASpec>() !.TheB, Is.SameAs(stObjs.Obtain <B>())); Assert.That(stObjs.ToHead(typeof(A)) !.GetStObjProperty("StObjPower"), Is.EqualTo("This is the A property.")); Assert.That(stObjs.ToHead(typeof(ASpec)) !.GetStObjProperty("StObjPower"), Is.EqualTo("ASpec level property.")); ASpec theA = (ASpec)stObjs.Obtain <A>() !; Assert.That(theA.StObjPower, Is.EqualTo("ASpec level property.")); Assert.That(typeof(A).GetProperty("StObjPower")?.GetValue(theA, null), Is.EqualTo("This is the A property.")); Assert.That(theA.StObjInitializeOnACalled, Is.False, "StObjInitialize is NOT called on setup instances."); } // Check generated StObjMap. { Debug.Assert(map != null); Assert.That(map.StObjs.Obtain <B>() !.TheA, Is.SameAs(map.StObjs.Obtain <A>()).And.SameAs(map.StObjs.Obtain <ASpec>())); Assert.That(map.StObjs.Obtain <ASpec>() !.TheB, Is.SameAs(map.StObjs.Obtain <B>())); ASpec theA = (ASpec)map.StObjs.Obtain <A>() !; theA.Should().NotBeNull(); Assert.That(theA.StObjPower, Is.EqualTo("ASpec level property.")); Assert.That(typeof(A).GetProperty("StObjPower")?.GetValue(theA, null), Is.EqualTo("This is the A property.")); Assert.That(theA.TheB, Is.SameAs(map.StObjs.Obtain <B>())); Assert.That(map.StObjs.Obtain <B>() !.TheInjectedA, Is.SameAs(theA)); Assert.That(theA.StObjInitializeOnACalled, Is.True); Assert.That(theA.StObjInitializeOnASpecCalled, Is.True); } }