public IEnumerator StepWithInitiallyCompletedConditionResetsCondition() { // Given a step with an already completed condition, Step step = new Step("Step1"); ICondition condition = new EndlessCondition(); condition.Autocomplete(); Transition transition = new Transition(); transition.Data.Conditions.Add(condition); step.Data.Transitions.Data.Transitions.Add(transition); step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When it is activated, step.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); step.Update(); } // Then the condition is reset to not completed. Assert.IsFalse(condition.IsCompleted); yield return(null); }
public IEnumerator InactiveConditionDoesntPreventCompletion() { EndlessCondition notOptional = new EndlessCondition(); // Given an activating transition with a condition, Transition transition = new Transition(); transition.Data.Conditions.Add(new OptionalEndlessCondition()); transition.Data.Conditions.Add(notOptional); transition.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); transition.LifeCycle.Activate(); while (transition.LifeCycle.Stage != Stage.Active) { yield return(null); transition.Update(); } // When the condition is skipped and the second condition is completed, transition.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessCondition>())); notOptional.Autocomplete(); yield return(null); transition.Update(); // Then the transition is completed. Assert.IsTrue(transition.IsCompleted); yield break; }
public IEnumerator StepWithCondition() { Step step = new Step("Step1"); EndlessCondition condition = new EndlessCondition(); Transition transition = new Transition(); transition.Data.Conditions.Add(condition); step.Data.Transitions.Data.Transitions.Add(transition); step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); step.LifeCycle.Activate(); while (step.LifeCycle.Stage != Stage.Active) { yield return(null); step.Update(); } Stage stepInitialStage = step.LifeCycle.Stage; Stage conditionInitialStage = condition.LifeCycle.Stage; bool conditionIsCompletedInitially = condition.IsCompleted; condition.Autocomplete(); bool conditionIsCompleted = condition.IsCompleted; step.LifeCycle.Deactivate(); while (step.LifeCycle.Stage != Stage.Inactive) { yield return(null); step.Update(); } Stage stepStageInEnd = step.LifeCycle.Stage; Stage conditionStageInEnd = condition.LifeCycle.Stage; bool conditionIsCompletedInEnd = condition.IsCompleted; // Check states were correct Assert.AreEqual(Stage.Active, stepInitialStage, "Step should be active initially"); Assert.AreEqual(Stage.Active, conditionInitialStage, "Condition should be active initially"); Assert.IsFalse(conditionIsCompletedInitially, "Condition should not completed initially"); Assert.IsTrue(conditionIsCompleted, "Condition should be completed now"); Assert.AreEqual(Stage.Inactive, stepStageInEnd, "Step should be inactive in the end"); Assert.AreEqual(Stage.Inactive, conditionStageInEnd, "Condition should not be active in the end"); Assert.IsTrue(conditionIsCompletedInEnd, "Condition should be completed in the end"); yield return(null); }
public IEnumerator MultiConditionTransitionFinishes() { // Given a transition with two conditions, EndlessCondition condition1 = new EndlessCondition(); EndlessCondition condition2 = new EndlessCondition(); Transition transition = new Transition(); transition.Data.Conditions.Add(condition1); transition.Data.Conditions.Add(condition2); transition.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // After it is activated and the conditions are completed, transition.LifeCycle.Activate(); yield return(null); transition.Update(); condition1.Autocomplete(); Assert.IsTrue(condition1.IsCompleted); Assert.IsFalse(condition2.IsCompleted); Assert.IsFalse(transition.IsCompleted); condition2.Autocomplete(); Assert.IsTrue(condition1.IsCompleted); Assert.IsTrue(condition2.IsCompleted); Assert.IsFalse(transition.IsCompleted); while (transition.IsCompleted == false) { yield return(null); transition.Update(); } // Then and only then the transition is completed. Assert.IsTrue(transition.IsCompleted); }
public IEnumerator LoopingStepsWithOneEndStep() { // Given a chapter with three steps // where the first two steps are connected to each other with two transitions with each one condition ("loop") // and the second step is connected to the third step with a third transition with one condition, Step step1 = new Step("First"); Step step2 = new Step("Second"); Step step3 = new Step("Third"); Chapter chapter = new Chapter("Chapter 1", step1); chapter.Data.Steps.Add(step2); chapter.Data.Steps.Add(step3); Transition transition1 = new Transition(); Transition transition2 = new Transition(); Transition transition3 = new Transition(); Transition transitionToEnd = new Transition(); transition1.Data.TargetStep = step2; transition2.Data.TargetStep = step1; transition3.Data.TargetStep = step3; EndlessCondition condition1 = new EndlessCondition(); EndlessCondition condition2 = new EndlessCondition(); EndlessCondition condition3 = new EndlessCondition(); transition1.Data.Conditions.Add(condition1); transition2.Data.Conditions.Add(condition2); transition3.Data.Conditions.Add(condition3); step1.Data.Transitions.Data.Transitions.Add(transition1); step2.Data.Transitions.Data.Transitions.Add(transition2); step2.Data.Transitions.Data.Transitions.Add(transition3); step3.Data.Transitions.Data.Transitions.Add(transitionToEnd); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter and complete the third condition after looping the first two steps once, chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition1.Autocomplete(); while (step2.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition2.Autocomplete(); while (step1.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition1.Autocomplete(); while (step2.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition3.Autocomplete(); while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } // Then the chapter and each step are deactivated. Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage, "Chapter should be active in the end"); Assert.AreEqual(Stage.Inactive, step1.LifeCycle.Stage, "Step1 should not be active in the end"); Assert.AreEqual(Stage.Inactive, step2.LifeCycle.Stage, "Step2 should not be active in the end"); Assert.AreEqual(Stage.Inactive, step3.LifeCycle.Stage, "Step3 should not be active in the end"); yield break; }
public IEnumerator LoopingStepsActivationStates() { // Given a chapter with two steps that have transitions with one condition to each other (a "loop"), Step step1 = new Step("First"); Step step2 = new Step("Second"); Chapter chapter = new Chapter("Looping Chapter", step1); chapter.Data.Steps.Add(step2); Transition transition1 = new Transition(); Transition transition2 = new Transition(); transition1.Data.TargetStep = step2; transition2.Data.TargetStep = step1; EndlessCondition condition1 = new EndlessCondition(); EndlessCondition condition2 = new EndlessCondition(); transition1.Data.Conditions.Add(condition1); transition2.Data.Conditions.Add(condition2); step1.Data.Transitions.Data.Transitions.Add(transition1); step2.Data.Transitions.Data.Transitions.Add(transition2); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter and complete every condition, chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterInitalStage = chapter.LifeCycle.Stage; Stage step1InitialStage = step1.LifeCycle.Stage; Stage step2InitialStage = step2.LifeCycle.Stage; condition1.Autocomplete(); while (step2.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageAfterFirstComplete = chapter.LifeCycle.Stage; Stage step1StageAfterFirstComplete = step1.LifeCycle.Stage; Stage step2StageAfterFirstComplete = step2.LifeCycle.Stage; condition2.Autocomplete(); while (step1.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageAfterSecondComplete = chapter.LifeCycle.Stage; Stage step1StageAfterSecondComplete = step1.LifeCycle.Stage; Stage step2StageAfterSecondComplete = step2.LifeCycle.Stage; // Then the first step is active again and every ActivationState after each condition completion has been correct. Assert.AreEqual(Stage.Activating, chapterInitalStage, "Chapter should be activating in the beginning"); Assert.AreEqual(Stage.Active, step1InitialStage, "First Step should be active in the beginning"); Assert.AreEqual(Stage.Inactive, step2InitialStage, "Second Step should be inactive in the beginning"); Assert.AreEqual(Stage.Activating, chapterStageAfterFirstComplete, "Chapter should be activating after first complete"); Assert.AreEqual(Stage.Inactive, step1StageAfterFirstComplete, "First Step should be deactivated after first complete"); Assert.AreEqual(Stage.Active, step2StageAfterFirstComplete, "Second Step should be active after first complete"); Assert.AreEqual(Stage.Activating, chapterStageAfterSecondComplete, "Chapter should not be activating after second complete because of the loop"); Assert.AreEqual(Stage.Active, step1StageAfterSecondComplete, "First Step should be active after second complete because of the loop"); Assert.AreEqual(Stage.Inactive, step2StageAfterSecondComplete, "Second Step should be deactivated after second complete because of the loop"); yield break; }