예제 #1
0
        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!");
        }
예제 #2
0
        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!");
        }
예제 #3
0
        public IEnumerator StepWithHighlightBehavior()
        {
            // Given a HighlightObjectBehavior with a HighlightProperty in a linear chapter.
            Color      highlightColor = Color.yellow;
            GameObject interactable   = GameObject.CreatePrimitive(PrimitiveType.Cube);

            interactable.name = targetName;
            DummyHighlightProperty  highlightProperty = interactable.AddComponent <DummyHighlightProperty>();
            HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor);

            TestLinearChapterBuilder chapterBuilder = TestLinearChapterBuilder.SetupChapterBuilder(1);

            chapterBuilder.Steps[0].Data.Behaviors.Data.Behaviors.Add(highlightBehavior);

            Chapter chapter = chapterBuilder.Build();

            chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate the chapter.
            chapter.LifeCycle.Activate();

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

                chapter.Update();
            }

            Stage highlightStageInStep          = highlightBehavior.LifeCycle.Stage;
            bool  objectHighlightedActiveInStep = highlightProperty.IsHighlighted;
            Color?colorInStep = highlightProperty.CurrentHighlightColor;

            chapter.Data.FirstStep.LifeCycle.Deactivate();

            while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Inactive)
            {
                yield return(null);

                chapter.Update();
            }

            Stage highlightStageAfterStep          = highlightBehavior.LifeCycle.Stage;
            bool  objectHighlightedActiveAfterStep = highlightProperty.IsHighlighted;
            Color?colorAfterStep = highlightProperty.CurrentHighlightColor;

            // Then the highlight behavior is active during the step and inactive after it.
            Assert.AreEqual(Stage.Active, highlightStageInStep, "The HighlightObjectBehavior should be active during step");
            Assert.IsTrue(objectHighlightedActiveInStep, "The HighlightProperty should be active during step");
            Assert.AreEqual(highlightColor, colorInStep, $"The highlight color should be {highlightColor}");

            Assert.AreEqual(Stage.Inactive, highlightStageAfterStep, "The HighlightObjectBehavior should be deactivated after step");
            Assert.IsFalse(objectHighlightedActiveAfterStep, "The HighlightProperty should be inactive after step");
            Assert.IsNull(colorAfterStep, "The highlight color should be null after deactivation of step.");
        }
예제 #4
0
        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);
        }
예제 #5
0
        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.");
        }
예제 #6
0
        public IEnumerator ActivationIsDone()
        {
            // Setup Chapter
            Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder(1, false).Build();

            // Activate should work on simple steps.
            CourseRunner.Initialize(new Course("Course", chapter));
            CourseRunner.Run();

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

            // Chapter should be finished now.
            Assert.AreEqual(Stage.Inactive, chapter.LifeCycle.Stage);
        }
예제 #7
0
        public IEnumerator OneChapterCourse()
        {
            Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build();
            Course  course   = new Course("MyCourse", chapter1);

            CourseRunner.Initialize(course);
            CourseRunner.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);
        }
예제 #8
0
        public IEnumerator FirstStepGetActivated()
        {
            // Setup Chapter
            Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder(3, true).Build();

            chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // 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");
        }
예제 #9
0
        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
            });

            CourseRunner.Initialize(course);
            CourseRunner.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);
        }
예제 #10
0
        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;
                }
            };

            CourseRunner.Initialize(course);
            CourseRunner.Run();

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

            Assert.IsTrue(wasStarted);
            Assert.IsTrue(wasCompleted);
        }
예제 #11
0
        public IEnumerator MultiStepChapterCompletesSteps()
        {
            // Setup Chapter
            TestLinearChapterBuilder builder = TestLinearChapterBuilder.SetupChapterBuilder(2, true);
            Chapter chapter = builder.Build();

            chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // 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");
        }