public ZenjectSceneLoader( SceneContext sceneRoot, ProjectKernel projectKernel) { _projectKernel = projectKernel; _sceneContainer = sceneRoot.Container; }
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.IsNull(_sceneContext); _sceneContext = SceneContext.Create(); _sceneContext.Install(); Assert.That(ProjectContext.HasInstance); Assert.IsEqual(shouldValidate, ProjectContext.Instance.Container.IsValidating); Assert.IsEqual(shouldValidate, _sceneContext.Container.IsValidating); }
protected void DestroyAll() { Assert.That(!_hasDestroyedAll, "Called DestroyAll twice in test '{0}'!", TestContext.CurrentContext.Test.Name); _hasDestroyedAll = true; Assert.That(_hasStartedInstall, "Called DestroyAll but did not call PreInstall (or SkipInstall) in test '{0}'!", TestContext.CurrentContext.Test.Name); // We need to use DestroyImmediate so that all the IDisposable's etc get processed immediately before // next test runs GameObject.DestroyImmediate(_sceneContext.gameObject); _sceneContext = null; var allRootObjects = new List <GameObject>(); // We want to clear all objects across all scenes to ensure the next test is not affected // at all by previous tests // TODO: How does this handle cases where the test loads other scenes? for (int i = 0; i < SceneManager.sceneCount; i++) { allRootObjects.AddRange( SceneManager.GetSceneAt(i).GetRootGameObjects()); } // We also want to destroy any objects marked DontDestroyOnLoad, especially ProjectContext allRootObjects.AddRange(ProjectContext.Instance.gameObject.scene.GetRootGameObjects()); foreach (var rootObj in allRootObjects) { // Make sure not to destroy the unity test runner objects that it adds if (!_unityTestRunnerObjects.Contains(rootObj)) { // Use DestroyImmediate for other objects too just to ensure we are fully // cleaned up before the next test starts GameObject.DestroyImmediate(rootObj); } } }