public IEnumerator UnskipChildNotBlockingActive()
        {
            // Given an active nonblocking behavior with an optional child,
            OptionalEndlessBehavior    optional = new OptionalEndlessBehavior();
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, false);

            behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>()));

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

                behavior.Update();
            }

            // When a new mode is set and the optional child has to be reactivated,
            behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>()));

            yield return(null);

            behavior.Update();

            // The child is activating.
            Assert.AreEqual(Stage.Activating, optional.LifeCycle.Stage);
            yield break;
        }
        public IEnumerator SkipChildNonBlockingActive()
        {
            // Given an active non-blocking behavior with an optional child,
            OptionalEndlessBehavior    optional = new OptionalEndlessBehavior();
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, false);

            behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            behavior.LifeCycle.Activate();
            optional.LifeCycle.MarkToFastForwardStage(Stage.Activating);

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

                behavior.Update();
            }

            // When a new mode is set and the optional child has to be skipped,
            behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>()));

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

                behavior.Update();
                Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage);
            }

            // The child is deactivated and behavior has finished it's activation.
            Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage);
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            yield break;
        }
        public IEnumerator SkipChildBlockingDeactivating()
        {
            // Given a deactivating blocking behavior with an optional child,
            OptionalEndlessBehavior    optional = new OptionalEndlessBehavior();
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, true);

            behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            behavior.LifeCycle.Activate();
            optional.LifeCycle.MarkToFastForwardStage(Stage.Activating);

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

                behavior.Update();
            }

            behavior.LifeCycle.Deactivate();
            optional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

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

                behavior.Update();
            }

            // When a new mode is set and the optional child has to be skipped,
            behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>()));

            // Wait a frame because configure doesn't even change anything about the stages.
            yield return(null);

            behavior.Update();

            // The child is deactivated and behavior has finished its deactivation.
            Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);
            yield break;
        }
        public IEnumerator BehaviorActivated()
        {
            // Given non-blocking behavior which wraps a behavior that is not activated immediately,
            EndlessBehavior            endlessBehavior = new EndlessBehavior();
            NonblockingWrapperBehavior behavior        = new NonblockingWrapperBehavior(endlessBehavior, false);

            behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            // When we activate it,
            behavior.LifeCycle.Activate();

            endlessBehavior.LifeCycle.MarkToFastForward();

            yield return(null);

            behavior.Update();

            yield return(null);

            behavior.Update();

            // Then it is activated.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
        }
        public IEnumerator SkipChildBlockingActivating()
        {
            // Given an activating blocking behavior with an optional child,
            OptionalEndlessBehavior    optional = new OptionalEndlessBehavior();
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, true);

            // When a new mode is set and the optional child has to be skipped,
            //RuntimeConfigurator.Configuration = new DynamicRuntimeConfiguration(new Mode("Test", new WhitelistTypeRule<IOptional>().Add<OptionalEndlessBehavior>()));
            behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>()));

            behavior.LifeCycle.Activate();

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

            // The child is deactivated and behavior has finished its activation.
            Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage);
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            yield break;
        }