public void AddComponent_DependencyIsInjected() { var sceneEventsProvider = new SceneEventsProviderMockup(); using (var sceneScope = new SceneScope(new Container(builder => builder.Register <IModule, TestModule>()), new Scene(), sceneEventsProvider, new LoggerMockup())) { var component = new TestComponentWithDependency(); sceneEventsProvider.TriggerComponentAdded(component); Assert.IsType <TestModule>(component.Module); Assert.Single(component.InitCalls); } }
public void SwitchScene_SceneScopeIsCreated() { var logger = new LoggerMockup(); var sceneScopeFactory = new SceneScopeFactoryMockup(); var moduleResources = new SingularityModules[0]; var sceneEventsProvider = new SceneEventsProviderMockup(); using (var scope = new GameScope(logger, sceneScopeFactory, sceneEventsProvider, moduleResources)) { sceneEventsProvider.TriggerEntered(); Assert.Single(sceneScopeFactory.CreateCalls); } }
public void AddGameObject_DependencyIsInjected() { var sceneEventsProvider = new SceneEventsProviderMockup(); using (var sceneScope = new SceneScope(new Container(builder => builder.Register <IModule, TestModule>()), new Scene(), sceneEventsProvider, new LoggerMockup())) { var gameObject = new GameObject("Test"); var testComponent = gameObject.AddComponent <TestComponentWithDependency>(); sceneEventsProvider.TriggerGameObjectsAdded(new List <GameObject> { gameObject }); Assert.IsType <TestModule>(testComponent.Module); Assert.Single(testComponent.InitCalls); } }
public void SceneIsDisposed_SceneScopeIsDiposed() { var logger = new LoggerMockup(); var sceneScopeFactory = new SceneScopeFactoryMockup(); var moduleResources = new SingularityModules[0]; var sceneEventsProvider = new SceneEventsProviderMockup(); using (var scope = new GameScope(logger, sceneScopeFactory, sceneEventsProvider, moduleResources)) { sceneEventsProvider.TriggerEntered(); SceneScope createdSceneScope = sceneScopeFactory.CreatedSceneScopes[0]; Assert.False(createdSceneScope.IsDisposed); sceneEventsProvider.TriggerLeaving(); Assert.True(createdSceneScope.IsDisposed); } }