public void DeactivateWhileNotActive() { // Setup Chapter Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder().Build(); bool didNotFail = false; bool isWrongException = false; // Expect to fail on calling Deactivate() before activating the Chapter. try { chapter.LifeCycle.Deactivate(); didNotFail = true; } catch (InvalidStateException) { // This is ok } catch (Exception) { isWrongException = true; } // Check if exception was thrown. Assert.IsFalse(didNotFail, "No Exception was raised!"); Assert.IsFalse(isWrongException, "Wrong Exception was raised!"); }
public void FirstStepIsSet() { TestLinearChapterBuilder builder = TestLinearChapterBuilder.SetupChapterBuilder(); Chapter chapter = builder.Build(); Assert.IsNotNull(chapter.Data.FirstStep, "First step not set!"); Assert.AreEqual(builder.Steps.First(), chapter.Data.FirstStep, "Wrong Step set as first!"); }
public void CanBeSetup() { Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build(); Chapter chapter2 = TestLinearChapterBuilder.SetupChapterBuilder().Build(); Course course = new Course("MyCourse", new List <IChapter> { chapter1, chapter2 }); Assert.AreEqual(chapter1, course.Data.FirstChapter); }
public void SetupTest() { Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder().Build(); // Name should be added to the Chapter Assert.AreEqual("Chapter1", chapter.Data.Name); // State is correct Assert.AreEqual(chapter.LifeCycle.Stage, Stage.Inactive, "Chapter should not be active"); // Assert that FirstStep is set Assert.IsNotNull(chapter.Data.FirstStep, "FirstStep is not null."); // Assert that CurrentStep is null Assert.IsNull(chapter.Data.Current, "Current is null."); }
public IEnumerator ActivationIsDone() { // Setup Chapter Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder(1, false).Build(); // Activate should work on simple steps. TrainingRunner.Initialize(new Course("Course", chapter)); TrainingRunner.Run(); while (chapter.LifeCycle.Stage != Stage.Inactive) { yield return(null); } // Chapter should be finished now. Assert.AreEqual(Stage.Inactive, chapter.LifeCycle.Stage); }
public IEnumerator FirstStepGetActivated() { // Setup Chapter Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder(3, true).Build(); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // Activate should work on simple steps. chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } // First Step should be active now. Assert.IsNotNull(chapter.Data.Current, "First step not set"); Assert.AreEqual(chapter.Data.Current.LifeCycle.Stage, Stage.Active, "First Step of Chapter was not activated"); }
public IEnumerator OneChapterCourse() { Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build(); Course course = new Course("MyCourse", chapter1); TrainingRunner.Initialize(course); TrainingRunner.Run(); Debug.Log(chapter1.LifeCycle.Stage); yield return(null); Assert.AreEqual(Stage.Activating, chapter1.LifeCycle.Stage); while (chapter1.LifeCycle.Stage != Stage.Inactive) { Debug.Log(chapter1.LifeCycle.Stage); yield return(null); } Assert.AreEqual(Stage.Inactive, chapter1.LifeCycle.Stage); }
public IEnumerator TwoChapterCourse() { Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build(); Chapter chapter2 = TestLinearChapterBuilder.SetupChapterBuilder().Build(); Course course = new Course("MyCourse", new List <IChapter> { chapter1, chapter2 }); TrainingRunner.Initialize(course); TrainingRunner.Run(); yield return(new WaitUntil(() => chapter1.LifeCycle.Stage == Stage.Activating)); Assert.AreEqual(Stage.Inactive, chapter2.LifeCycle.Stage); yield return(new WaitUntil(() => chapter2.LifeCycle.Stage == Stage.Activating)); Assert.AreEqual(Stage.Inactive, chapter1.LifeCycle.Stage); Assert.AreEqual(Stage.Activating, chapter2.LifeCycle.Stage); }
public IEnumerator EventsAreThrown() { Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build(); Chapter chapter2 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build(); Course course = new Course("MyCourse", new List <IChapter> { chapter1, chapter2 }); bool wasStarted = false; bool wasCompleted = false; course.LifeCycle.StageChanged += (obj, args) => { if (args.Stage == Stage.Activating) { wasStarted = true; } else if (args.Stage == Stage.Active) { wasCompleted = true; } }; TrainingRunner.Initialize(course); TrainingRunner.Run(); while (course.LifeCycle.Stage != Stage.Inactive) { yield return(null); } Assert.IsTrue(wasStarted); Assert.IsTrue(wasCompleted); }
public IEnumerator MultiStepChapterCompletesSteps() { // Setup Chapter TestLinearChapterBuilder builder = TestLinearChapterBuilder.SetupChapterBuilder(2, true); Chapter chapter = builder.Build(); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // Activate should work on simple steps. chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterInitalStage = chapter.LifeCycle.Stage; Stage step1InitialStage = builder.Steps[0].LifeCycle.Stage; Stage step2InitialStage = builder.Steps[1].LifeCycle.Stage; builder.StepTriggerConditions[0].Autocomplete(); while (chapter.Data.Steps[1].LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageAfterFirstComplete = chapter.LifeCycle.Stage; Stage step1StageAfterFirstComplete = builder.Steps[0].LifeCycle.Stage; Stage step2StageAfterFirstComplete = builder.Steps[1].LifeCycle.Stage; builder.StepTriggerConditions[1].Autocomplete(); while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageInEnd = chapter.LifeCycle.Stage; Stage step1StageInEnd = builder.Steps[0].LifeCycle.Stage; Stage step2StageInEnd = builder.Steps[1].LifeCycle.Stage; // check steps are activated and completed in correct order Assert.AreEqual(Stage.Activating, chapterInitalStage, "Chapter should be active in the beginning"); Assert.AreEqual(Stage.Active, step1InitialStage, "First Step should be active in the beginning"); Assert.AreEqual(Stage.Inactive, step2InitialStage, "Second Step should not be active in the beginning"); Assert.AreEqual(Stage.Activating, chapterStageAfterFirstComplete, "Chapter should be active after first complete"); Assert.AreEqual(Stage.Inactive, step1StageAfterFirstComplete, "First Step should not be active after first complete"); Assert.AreEqual(Stage.Active, step2StageAfterFirstComplete, "Second Step should be active after first complete"); Assert.AreEqual(Stage.Active, chapterStageInEnd, "Chapter should still be active, as nothing deactivated it."); Assert.AreEqual(Stage.Inactive, step1StageInEnd, "First Step should not be active in the end"); Assert.AreEqual(Stage.Inactive, step2StageInEnd, "Second Step should not be active in the end"); }