Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }