public SceneContextRegistryAdderAndRemover(
     SceneContext sceneContext,
     SceneContextRegistry registry)
 {
     _registry     = registry;
     _sceneContext = sceneContext;
 }
Example #2
0
 public UniDiSceneLoader(
     [InjectOptional]
     SceneContext sceneRoot,
     ProjectKernel projectKernel)
 {
     _projectKernel  = projectKernel;
     _sceneContainer = sceneRoot == null ? null : sceneRoot.Container;
 }
Example #3
0
        public void Remove(SceneContext context)
        {
            bool removed = _map.Remove(context.gameObject.scene);

            if (!removed)
            {
                Log.Warn("Failed to remove SceneContext from SceneContextRegistry");
            }
        }
Example #4
0
        public IEnumerator LoadScenes(params string[] sceneNames)
        {
            Assert.That(!_hasLoadedScene, "Attempted to load scene twice!");
            _hasLoadedScene = true;

            // Clean up any leftovers from previous test
            UniDiTestUtil.DestroyEverythingExceptTestRunner(false);

            Assert.That(SceneContainers.IsEmpty());

            for (int i = 0; i < sceneNames.Length; i++)
            {
                var sceneName = sceneNames[i];

                Assert.That(Application.CanStreamedLevelBeLoaded(sceneName),
                            "Cannot load scene '{0}' for test '{1}'.  The scenes used by SceneTestFixture derived classes must be added to the build settings for the test to work",
                            sceneName, GetType());

                Log.Info("Loading scene '{0}' for testing", sceneName);

                var loader = SceneManager.LoadSceneAsync(sceneName, i == 0 ? LoadSceneMode.Single : LoadSceneMode.Additive);

                while (!loader.isDone)
                {
                    yield return(null);
                }

                SceneContext sceneContext = null;

                if (ProjectContext.HasInstance)
                // ProjectContext might be null if scene does not have a scene context
                {
                    var scene = SceneManager.GetSceneByName(sceneName);

                    sceneContext = ProjectContext.Instance.Container.Resolve <SceneContextRegistry>()
                                   .TryGetSceneContextForScene(scene);
                }

                _sceneContainers.Add(sceneContext == null ? null : sceneContext.Container);
            }

            _sceneContainer = _sceneContainers.Where(x => x != null).LastOrDefault();

            if (_sceneContainer != null)
            {
                _sceneContainer.Inject(this);
            }
        }
Example #5
0
        protected void PreInstall()
        {
            Assert.That(!_hasStartedInstall, "Called PreInstall twice in test '{0}'!", TestContext.CurrentContext.Test.Name);
            _hasStartedInstall = true;

            Assert.That(!ProjectContext.HasInstance);

            var shouldValidate = CurrentTestHasAttribute <ValidateOnlyAttribute>();

            ProjectContext.ValidateOnNextRun = shouldValidate;

            Assert.That(_sceneContext == null);

            _sceneContext = SceneContext.Create();
            _sceneContext.Install();

            Assert.That(ProjectContext.HasInstance);

            Assert.IsEqual(shouldValidate, ProjectContext.Instance.Container.IsValidating);
            Assert.IsEqual(shouldValidate, _sceneContext.Container.IsValidating);
        }
Example #6
0
        void DestroyEverythingInternal(bool immediate)
        {
            if (_sceneContext != null)
            {
                // We need to use DestroyImmediate so that all the IDisposable's etc get processed immediately before
                // next test runs
                if (immediate)
                {
                    GameObject.DestroyImmediate(_sceneContext.gameObject);
                }
                else
                {
                    GameObject.Destroy(_sceneContext.gameObject);
                }

                _sceneContext = null;
            }

            UniDiTestUtil.DestroyEverythingExceptTestRunner(immediate);
            StaticContext.Clear();
        }
Example #7
0
 public void Add(SceneContext context)
 {
     Assert.That(!_map.ContainsKey(context.gameObject.scene));
     _map.Add(context.gameObject.scene, context);
 }