Beispiel #1
0
        public IEnumerator TextToSpeechAudio()
        {
            // Given we have TextToSpeechAudio instance,
            TextToSpeechAudio audio = new TextToSpeechAudio(new LocalizedString("TestPath"));

            ICourse course = new LinearTrainingBuilder("Training")
                             .AddChapter(new LinearChapterBuilder("Chapter")
                                         .AddStep(new BasicStepBuilder("Step")
                                                  .DisableAutomaticAudioHandling()
                                                  .AddBehavior(new PlayAudioBehavior(audio, BehaviorExecutionStages.Activation))))
                             .Build();

            // When we serialize and deserialize a training with it,
            ICourse testCourse = JsonTrainingSerializer.Deserialize(JsonTrainingSerializer.Serialize(course));

            // Then the text to generate sound from should be the same.
            IAudioData data1 = ((PlayAudioBehavior)course.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First()).Data.AudioData;
            IAudioData data2 = ((PlayAudioBehavior)testCourse.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First()).Data.AudioData;

            string audioPath1 = TestingUtils.GetField <LocalizedString>(data1, "text").Key;
            string audioPath2 = TestingUtils.GetField <LocalizedString>(data2, "text").Key;

            Assert.AreEqual(data1.GetType(), data2.GetType());

            Assert.AreEqual(audioPath1, "TestPath");
            Assert.AreEqual(audioPath1, audioPath2);

            return(null);
        }
        public IEnumerator ResourceAudio()
        {
            // Given we have a ResourceAudio instance,
            ResourceAudio audio = new ResourceAudio(new LocalizedString("TestPath"));

            ICourse course = new LinearTrainingBuilder("Training")
                             .AddChapter(new LinearChapterBuilder("Chapter")
                                         .AddStep(new BasicStepBuilder("Step")
                                                  .AddBehavior(new PlayAudioBehavior(audio, BehaviorExecutionStages.Activation))))
                             .Build();

            // When we serialize and deserialize a training with it
            ICourse testCourse = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(course));

            // Then the path to audio resource should be the same.
            string audioPath1 = TestingUtils.GetField <LocalizedString>(((PlayAudioBehavior)course.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First()).Data.AudioData, "path").Key;
            string audioPath2 = TestingUtils.GetField <LocalizedString>(((PlayAudioBehavior)testCourse.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First()).Data.AudioData, "path").Key;

            Assert.AreEqual(audioPath1, audioPath2);

            return(null);
        }
        public IEnumerator PlayAudioOnDectivationBehavior()
        {
            // Given a training with PlayAudioOnDeactivationBehavior and some ResourceData,
            ICourse training1 = new LinearTrainingBuilder("Training")
                                .AddChapter(new LinearChapterBuilder("Chapter")
                                            .AddStep(new BasicStepBuilder("Step")
                                                     .AddBehavior(new PlayAudioBehavior(new ResourceAudio(new LocalizedString("TestPath")), BehaviorExecutionStages.Activation))))
                                .Build();

            // When we serialize and deserialize it,
            ICourse training2 = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(training1));

            PlayAudioBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as PlayAudioBehavior;
            PlayAudioBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as PlayAudioBehavior;

            // Then path to audio file should not change.
            Assert.IsNotNull(behavior1);
            Assert.IsNotNull(behavior2);
            Assert.AreEqual(TestingUtils.GetField <LocalizedString>(behavior1.Data.AudioData, "path").Key, TestingUtils.GetField <LocalizedString>(behavior2.Data.AudioData, "path").Key);

            return(null);
        }