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;
        }
Ejemplo n.º 3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            object deserialized = serializer.Deserialize(reader);

            NonblockingWrapperBehavior obsoleteBehavior = deserialized as NonblockingWrapperBehavior;

            if (obsoleteBehavior == null)
            {
                return(deserialized);
            }
            else
            {
                IBehavior properBehavior             = obsoleteBehavior.Data.Behavior;
                IBackgroundBehaviorData blockingData = properBehavior.Data as IBackgroundBehaviorData;
                if (blockingData != null)
                {
                    blockingData.IsBlocking = obsoleteBehavior.Data.IsBlocking;
                }

                return(properBehavior);
            }
        }
        public IEnumerator BlockingBehaviorActivating()
        {
            // Given blocking behavior which wraps a behavior that is not activated immediately,
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(new EndlessBehavior(), true);

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

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

            // Then it is immediately activated.
            Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator WrappedBehaviorActivating()
        {
            // Given non-blocking behavior which wraps a behavior that is not activated immediately,
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(new EndlessBehavior(), false);

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

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

            // Then wrapped behavior starts its activation.
            Assert.AreEqual(Stage.Activating, behavior.Data.Behavior.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator FastForwardInactiveBehavior()
        {
            // Given non-blocking behavior which wraps a behavior that is not activated immediately,
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(new EndlessBehavior(), false);

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

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

            // Then it doesn't autocomplete because it hasn't been activated yet.
            Assert.AreEqual(Stage.Inactive, behavior.Data.Behavior.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator FastForwardInactiveBehaviorAndActivateIt()
        {
            // Given non-blocking behavior which wraps a behavior that is not activated immediately,
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(new EndlessBehavior(), false);

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

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

            // Then the behavior and its wrapped behavior should be activated immediately.
            Assert.AreEqual(Stage.Active, behavior.Data.Behavior.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 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;
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public IEnumerator NonblockingWrapperBehaviorIsConverted()
        {
            // Given a training with the obsolete NonblockingWapperBehavior where isBlocking is true, which wraps a non-blocking behavior,
#pragma warning disable 618
            NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(new EndlessBehavior(false), true);
#pragma warning restore 618

            ICourse course = new LinearTrainingBuilder("Training")
                             .AddChapter(new LinearChapterBuilder("Chapter")
                                         .AddStep(new BasicStepBuilder("Step")
                                                  .DisableAutomaticAudioHandling()
                                                  .AddBehavior(behavior)))
                             .Build();

            // When we serialize and deserialize it,
            ICourse deserializedCourse = JsonTrainingSerializer.Deserialize(JsonTrainingSerializer.Serialize(course));

            EndlessBehavior deserializedBehavior = deserializedCourse.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as EndlessBehavior;

            // Then the NonblockingWrapperBehavior is converted to the actual wrapped behavior and the "IsBlocking" property returns true.
            Assert.IsNotNull(deserializedBehavior);
            Assert.IsTrue(deserializedBehavior.Data.IsBlocking);
            yield break;
        }