public void TestSystemsNotDuplicated() { ITestSystem1 system1 = Substitute.For <ITestSystem1>(); ITestSystem2 system2 = Substitute.For <ITestSystem2>(); ITestSystem3 system3 = Substitute.For <ITestSystem3>(); ITestSystem4 system4 = Substitute.For <ITestSystem4>(); system1.GetDependencies(); system2.GetDependencies().Returns(new Type[] { typeof(ITestSystem1) }); system3.GetDependencies().Returns(new Type[] { typeof(ITestSystem1), typeof(ITestSystem2) }); system4.GetDependencies().Returns(new Type[] { typeof(ITestSystem2), typeof(ITestSystem3) }); var context = new SystemContext(); context.Register <ITestSystem1>(() => system1); context.Register <ITestSystem2>(() => system2); context.Register <ITestSystem3>(() => system3); context.Register <ITestSystem4>(() => system4); var container = new SystemContainer(); container.SetContext(context); Assert.IsTrue(container.Init()); system1.ReceivedWithAnyArgs(1).Init(null); system2.ReceivedWithAnyArgs(1).Init(null); system3.ReceivedWithAnyArgs(1).Init(null); system4.ReceivedWithAnyArgs(1).Init(null); }
private void HandleTransitionOutFinished() { _currentTransitionController.TransitionOutFinished -= HandleTransitionOutFinished; if (_currentState != null) { _currentState.Exit(); // TODO: This would be a good place for GC if that becomes // something we actually need to wory about. // Shutdown old systems _systems.Shutdown(); } // Setup new systems _systems = new SystemContainer(); SystemContext context = _nextState.GetSystemContext(); context.RegisterWeak(FrameworkSystems); _systems.SetContext(context); if (!_systems.Init()) { _logger.LogError("Failed to init game state systems"); HandleFailedToTransition(); } _currentState = _nextState; _nextState.ReadyToTransitionIn += HandleGameStateReady; _nextState.Enter(_systems); }
public void TestCircularDependency() { ITestSystem1 system1 = Substitute.For <ITestSystem1>(); ITestSystem2 system2 = Substitute.For <ITestSystem2>(); system1.GetDependencies().Returns(new Type[] { typeof(ITestSystem2) }); system2.GetDependencies().Returns(new Type[] { typeof(ITestSystem1) }); var context = new SystemContext(); context.Register <ITestSystem1>(() => system1); context.Register <ITestSystem2>(() => system2); var container = new SystemContainer(); container.SetContext(context); Assert.IsFalse(container.Init()); }