Esempio n. 1
0
        public void MergeActivitiesReturnsSingleActivityAddingSpeakSsmlTag()
        {
            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text("This is the single activity", "This is<break strength=\"strong\"/>the SSML");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(inputActivity, processActivityResult);
        }
        public void MergeActivitiesReturnsCorrectlyJoinedText()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var firstActivity  = MessageFactory.Text("This is the first activity.");
            var secondActivity = MessageFactory.Text("This is the second activity");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.MergedActivity.Text);
        }
Esempio n. 3
0
        public void MergeActivitiesTextWithNoPeriodAndEmptyText()
        {
            var alexaAdapter   = new AlexaRequestMapper();
            var firstActivity  = MessageFactory.Text("This is the first activity");
            var secondActivity = MessageFactory.Text("");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            // We want to preserve the missing period here even though it is merged with empty text.
            Assert.Equal("This is the first activity", processActivityResult.MergedActivity.Text);
        }
        public void MergeActivitiesWithEndOfConversationOnly()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var activity = (Activity)Activity.CreateEndOfConversationActivity();

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                activity
            });

            // Empty merged activities.
            Assert.NotNull(processActivityResult);
            Assert.Null(processActivityResult.MergedActivity);
            Assert.True(processActivityResult.EndOfConversationFlagged);
        }
        public void MergeActivitiesIgnoresNonMessageActivities()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var firstActivity  = MessageFactory.Text("This is the first activity.");
            var traceActivity  = Activity.CreateTraceActivity("This is a trace") as Activity;
            var secondActivity = MessageFactory.Text("This is the second activity");
            var typingActivity = Activity.CreateTypingActivity() as Activity;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, traceActivity, secondActivity, typingActivity
            });

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.Text);
        }
        public void MergeActivitiesReturnsSingleActivityAddingSpeakSsmlTag()
        {
            const string text = "This is the single activity";
            const string ssml = "This is<break strength=\"strong\"/>the SSML";

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            Assert.Equal($"<speak>{ssml}</speak>", processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesReturnIdenticalSingleActivityNoSsml()
        {
            const string text = "This is the single activity";
            const string ssml = null;

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            Assert.Equal(ssml, processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesJoinedTextWithEndOfConversation()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var activites = new List <Activity>()
            {
                MessageFactory.Text("This is the first activity."),
                (Activity)Activity.CreateEndOfConversationActivity(),
                MessageFactory.Text("This is the second activity")
            };

            var processActivityResult = alexaAdapter.MergeActivities(activites);

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.MergedActivity.Text);
            Assert.True(processActivityResult.EndOfConversationFlagged);
        }
Esempio n. 9
0
        public void MergeActivitiesReturnsSingleActivityWithComplexSpeakSsmlTag()
        {
            const string text = "Microsoft Ignite will take place online";
            const string ssml = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\"><voice name=\"en-US-AriaNeural\">Microsoft Ignite will take place online</voice></speak>";

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            // When removing the speak tag the serializer adds the missing space at the end of the xml element. This doesn't matter for rendering in Alexa so it is fine.
            Assert.Equal("<speak>Microsoft Ignite will take place online</speak>", processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesReturnsIdenticalSingleActivityWithSpeakSsmlTag()
        {
            const string text = "This is the single activity";
            const string ssml = "<speak>This is<break strength=\"strong\"/>the SSML</speak>";

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            // When removing the speak tag the serializer adds the missing space at the end of the xml element. This doesn't matter for rendering in Alexa so it is fine.
            Assert.Equal(ssml.Replace("/>", " />"), processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesReturnsCorrectlyJoinedSpeakWithSsml()
        {
            var alexaAdapter = new AlexaRequestMapper();

            // Note: The input activities deliberately have an activity where the speak tag
            // is included and one activity where it is not, to ensure the stripping / wrapping
            // of the speak tag is handled correctly.
            var firstActivity  = MessageFactory.Text("This is the first activity.", "This is<break strength=\"strong\"/>the first activity SSML");
            var secondActivity = MessageFactory.Text("This is the second activity.", "<speak>This is the second activity SSML</speak>");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("<speak>This is<break strength=\"strong\"/>the first activity SSML<break strength=\"strong\"/>This is the second activity SSML</speak>",
                         processActivityResult.Speak);
        }
        public void MergeActivitiesReturnsCorrectlyInconsistentPeriods()
        {
            var alexaAdapter = new AlexaRequestMapper();

            // Note: The input activities deliberately have an activity where the speak tag
            // is included and one activity where it is not, to ensure the stripping / wrapping
            // of the speak tag is handled correctly.
            var firstActivity  = MessageFactory.Text("This is the first activity.", "This is<break strength=\"strong\"/>the first activity SSML");
            var secondActivity = MessageFactory.Attachment(new HeroCard("test", "test").ToAttachment()) as Activity;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("<speak>This is<break strength=\"strong\"/>the first activity SSML</speak>", processActivityResult.MergedActivity.Speak);
            Assert.Equal("This is the first activity.", processActivityResult.MergedActivity.Text);
            Assert.False(processActivityResult.EndOfConversationFlagged);
        }
        public void MergeActivitiesAttachmentAndPlainText()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var attachment = new Attachment
            {
                Name        = "Attachment1.jpg",
                ContentType = "image/jpeg",
                Content     = "https://somefantasticurl/",
            };
            var firstActivity  = MessageFactory.Text(JsonConvert.SerializeObject(attachment, HttpHelper.BotMessageSerializerSettings));
            var secondActivity = (Activity)MessageFactory.Attachment(attachment);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity> {
                firstActivity, secondActivity
            });

            Assert.Equal("{   \"contentType\": \"image/jpeg\",   \"content\": \"https://somefantasticurl/\",   \"name\": \"Attachment1.jpg\" }", processActivityResult.MergedActivity.Text);
        }
        public void AppostrophiesNotConvertedNonSsml()
        {
            const string text         = "It's amazing <xml />";
            var          alexaAdapter = new AlexaRequestMapper();

            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Text = text;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                activity
            });

            var skillResponse = ExecuteActivityToResponse(mapper, processActivityResult, skillRequest);

            VerifyPlainTextResponse(skillResponse, text);
        }
        public void AppostrophiesNotConvertedSsml()
        {
            const string text         = "It's amazing <break /> really";
            var          alexaAdapter = new AlexaRequestMapper();

            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Speak = text;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                activity
            });

            var skillResponse = ExecuteActivityToResponse(mapper, processActivityResult, skillRequest);
            var outputSpeech  = skillResponse.Response.OutputSpeech as SsmlOutputSpeech;

            Assert.Equal($"<speak>{text}</speak>", outputSpeech.Ssml);
        }
        public void MergeActivitiesMergesAttachments()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var firstActivity  = MessageFactory.Text("This is the first activity.");
            var secondActivity = MessageFactory.Text("This is the second activity");

            firstActivity.Attachments.Add(new SimpleCard {
                Title = "Simple card title", Content = "Test content"
            }.ToAttachment());
            secondActivity.Attachments = null;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.MergedActivity.Text);
            Assert.NotNull(processActivityResult.MergedActivity.Attachments);
            Assert.Equal(1, processActivityResult.MergedActivity.Attachments.Count);
            Assert.Equal(AlexaAttachmentContentTypes.Card, processActivityResult.MergedActivity.Attachments[0].ContentType);
        }
        public void MergeActivitiesCorrectlyConvertsMarkdownToPlainText()
        {
            var alexaAdapter = new AlexaRequestMapper();

            // Note: The input activities deliberately have an activity where the speak tag
            // is included and one activity where it is not, to ensure the stripping / wrapping
            // of the speak tag is handled correctly.

            var message = new StringBuilder();

            message.AppendLine("**This** ~~is~~ ***the*** first activity.");
            message.AppendLine("# Heading 1");
            message.AppendLine("This is another paragraph.");
            message.AppendLine("- Item 1");
            message.AppendLine("- Item 2");
            message.AppendLine("- Item 3");
            message.AppendLine("");
            message.AppendLine("## Heading 2");
            message.AppendLine("1. Item 1");
            message.AppendLine("2. Item 2");
            message.AppendLine("3. Item 3");
            message.AppendLine("");
            message.AppendLine("More info [visit our web site](www.microsoft.com)");

            var firstActivity  = MessageFactory.Text(message.ToString(), "This is<break strength=\"strong\"/>the first activity SSML");
            var secondActivity = MessageFactory.Text("This is the second activity.", "<speak>This is the second activity SSML</speak>");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("This is the first activity. Heading 1. This is another paragraph. Item 1, Item 2, Item 3. Heading 2. 1. Item 1, 2. Item 2, 3. Item 3. More info visit our web site www.microsoft.com. This is the second activity.",
                         processActivityResult.MergedActivity.Text);

            Assert.Equal("<speak>This is<break strength=\"strong\"/>the first activity SSML<break strength=\"strong\"/>This is the second activity SSML</speak>",
                         processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesReturnsNullWithNoActivities()
        {
            var alexaAdapter = new AlexaRequestMapper();

            Assert.Null(alexaAdapter.MergeActivities(new List <Activity>()));
        }
 public virtual Activity ProcessOutgoingActivities(List <Activity> activities)
 {
     return(_requestMapper.MergeActivities(activities));
 }