public IEnumerator FastForwardActive() { // Given a step, IBehavior behavior = new EndlessBehavior(); ICondition condition = new EndlessCondition(); Transition transition = new Transition(); IStep step = new Step("Step"); transition.Data.Conditions.Add(condition); step.Data.Behaviors.Data.Behaviors.Add(behavior); step.Data.Transitions.Data.Transitions.Add(transition); step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); step.LifeCycle.Activate(); // When you fast-forward it, step.LifeCycle.MarkToFastForward(); // Then everything is completed. Assert.AreEqual(Stage.Active, step.LifeCycle.Stage); Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage); yield break; }
public IEnumerator ConditionsActivateOnlyAfterBehaviors() { Step step = new Step("Step1"); EndlessCondition condition = new EndlessCondition(); EndlessBehavior behavior = new EndlessBehavior(); Transition transition = new Transition(); transition.Data.Conditions.Add(condition); step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(behavior); step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); step.LifeCycle.Activate(); while (behavior.LifeCycle.Stage != Stage.Activating) { Assert.AreEqual(Stage.Activating, step.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, condition.LifeCycle.Stage); yield return(null); step.Update(); } behavior.LifeCycle.MarkToFastForwardStage(Stage.Activating); while (condition.LifeCycle.Stage != Stage.Active) { Assert.AreEqual(Stage.Activating, step.LifeCycle.Stage); yield return(null); step.Update(); } }
public IEnumerator FastForwardNextStage() { // Given an entity, IEntity entity = new EndlessBehavior(); entity.LifeCycle.Activate(); Assert.AreEqual(Stage.Activating, entity.LifeCycle.Stage); // When you fast-forward its next stage, entity.LifeCycle.MarkToFastForwardStage(Stage.Active); // Then the current stage is not fast-forwarded. Assert.AreEqual(Stage.Activating, entity.LifeCycle.Stage); yield break; }
public IEnumerator FastForwardInactive() { // Given a step, IBehavior behavior = new EndlessBehavior(); ICondition condition = new EndlessCondition(); Transition transition = new Transition(); IStep step = new Step("Step"); transition.Data.Conditions.Add(condition); step.Data.Behaviors.Data.Behaviors.Add(behavior); step.Data.Transitions.Data.Transitions.Add(transition); step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When you fast-forward it, step.LifeCycle.MarkToFastForward(); // Then it doesn't change it's activation state, as well as its contents. Assert.AreEqual(Stage.Inactive, step.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, condition.LifeCycle.Stage); yield break; }
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; }