public IEnumerator NotExistingPrefab()
        {
            // Given the position provider training object, an invalid path to a not existing prefab, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToMockPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait for one update cycle,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            yield return(null);

            behavior.Update();

            string     prefabName = "Behavior" + pathToMockPrefab.Substring(pathToMockPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            // Then the activation state of the behavior is "active" and there is no confetti machine in the scene.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.AreEqual(null, machine);
        }
        public IEnumerator StillActivatingWhenPositiveDurationNotFinished()
        {
            // Given the position provider training object, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, 2f, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // And wait two update cycles,
            yield return(null);

            behavior.Update();

            yield return(null);

            behavior.Update();

            // Then the activation state of the behavior is "activating".
            Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
        }
        public IEnumerator ActivationWithSpawnedMachine()
        {
            // Given a positive duration, a position provider, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait until it's activating,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            string     prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            // Then the activation state of the behavior is "activating" and the ConfettiMachine exists in the scene.
            Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
            Assert.IsTrue(machine != null);
        }
        public IEnumerator FastForwardActivatingBehavior()
        {
            // Given an active ConfettiBehavior with activation mode "Activation",
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // When we mark it to fast-forward,
            behavior.LifeCycle.MarkToFastForward();

            // Then it autocompletes immediately.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
        }
        public IEnumerator ZeroDuration()
        {
            // Given a duration equals zero, a position provider, some valid default settings, and the activation mode = Activation,
            float newDuration = 0f;

            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, newDuration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // Wait one update cycle,
            yield return(null);

            behavior.Update();

            // And wait one end cycle,
            yield return(null);

            behavior.Update();

            // Then behavior activation is immediately completed, and the confetti machine should be in the scene.
            string     prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsTrue(machine == null);

            // Cleanup created game objects.
            Object.DestroyImmediate(target);
        }
        public IEnumerator RemovedMachineAfterPositiveDuration()
        {
            // Given a positive duration, a position provider, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait for one update cycle,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            yield return(null);

            behavior.Update();

            // And wait duration seconds,
            float startTime = Time.time;

            while (Time.time < startTime + duration + 0.1f)
            {
                yield return(null);

                behavior.Update();
            }

            // Then behavior activation is completed, and the confetti machine should be deleted.
            string prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);

            Assert.IsTrue(GameObject.Find(prefabName) == null);
        }
        public IEnumerator IsActiveAfterPositiveDuration()
        {
            // Given the position provider training object, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait for one update cycle,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // And wait for it to be active,
            float startTime = Time.time;

            while (behavior.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                behavior.Update();
            }

            float behaviorDuration = Time.time - startTime;

            // Then the activation state of the behavior is "active" after the expected duration.
            Assert.AreEqual(duration, behaviorDuration, Time.deltaTime);
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
        }
        public IEnumerator SpawnAtPositionProvider()
        {
            // Given the position provider training object, some valid default settings, and the activation mode = Activation,
            GameObject target = new GameObject(positionProviderName);

            target.transform.position = new Vector3(5, 10, 20);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // And wait one update cycle,
            yield return(null);

            behavior.Update();

            // Then the confetti machine is at the same position as the position provider
            string     prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            Assert.IsFalse(machine == null);
            Assert.IsTrue(machine.transform.position == target.transform.position);
        }