Exemplo n.º 1
0
        public async Task Test_Onboarding_Flow()
        {
            var testName = "Jane Doe";

            var profileState = new UserProfileState();

            profileState.Name = testName;

            var allNamePromptVariations  = AllResponsesTemplates.ExpandTemplate("NamePrompt");
            var allHaveMessageVariations = AllResponsesTemplates.ExpandTemplate("HaveNameMessage", profileState);

            dynamic data = new JObject();

            data.name = testName;

            await GetTestFlow(includeUserProfile : false)
            .Send(new Activity()
            {
                Type         = ActivityTypes.ConversationUpdate,
                MembersAdded = new List <ChannelAccount>()
                {
                    new ChannelAccount("user")
                }
            })
            .AssertReply(activity => Assert.AreEqual(1, activity.AsMessageActivity().Attachments.Count))
            .AssertReplyOneOf(allNamePromptVariations.Cast <string>().ToArray())
            .Send(testName)
            .AssertReplyOneOf(allHaveMessageVariations.Cast <string>().ToArray())
            .StartTestAsync();
        }
Exemplo n.º 2
0
        public async Task Test_Localization_French()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("fr-fr");

            var allIntroCardTitleVariations = AllResponsesTemplates.ExpandTemplate("NewUserIntroCardTitle");

            await GetTestFlow(includeUserProfile : false)
            .Send(new Activity()
            {
                Type         = ActivityTypes.ConversationUpdate,
                MembersAdded = new List <ChannelAccount>()
                {
                    new ChannelAccount("user")
                }
            })
            .AssertReply(activity =>
            {
                // Assert there is a card in the message
                Assert.AreEqual(1, activity.AsMessageActivity().Attachments.Count);

                // Assert the intro card has been localized
                var content = JsonConvert.SerializeObject(activity.AsMessageActivity().Attachments[0].Content);
                var card    = AdaptiveCard.FromJson(content).Card;

                Assert.IsTrue(card.Body.Any(i => i.Type == "Container" && ((AdaptiveContainer)i).Items.Any(t => t.Type == "TextBlock" && allIntroCardTitleVariations.Contains(((AdaptiveTextBlock)t).Text))));
            })
            .StartTestAsync();
        }
        public async Task Test_Repeat_Interruption()
        {
            var allNamePromptVariations = AllResponsesTemplates.ExpandTemplate("NamePrompt");

            await GetTestFlow(includeUserProfile : false)
            .Send(string.Empty)
            .AssertReplyOneOf(allNamePromptVariations.Cast <string>().ToArray())
            .Send(GeneralUtterances.Repeat)
            .AssertReplyOneOf(allNamePromptVariations.Cast <string>().ToArray())
            .StartTestAsync();
        }
        public async Task Test_Help_Interruption()
        {
            var allFirstPromptVariations = AllResponsesTemplates.ExpandTemplate("FirstPromptMessage");

            await GetTestFlow()
            .Send(string.Empty)
            .AssertReplyOneOf(allFirstPromptVariations.Cast <string>().ToArray())
            .Send(GeneralUtterances.Help)
            .AssertReply(activity => Assert.AreEqual(1, activity.AsMessageActivity().Attachments.Count))
            .StartTestAsync();
        }
        public async Task Test_Cancel_Interruption()
        {
            var allFirstPromptVariations = AllResponsesTemplates.ExpandTemplate("FirstPromptMessage");
            var allResponseVariations    = AllResponsesTemplates.ExpandTemplate("CancelledMessage", TestUserProfileState);

            await GetTestFlow()
            .Send(string.Empty)
            .AssertReplyOneOf(allFirstPromptVariations.Cast <string>().ToArray())
            .Send(GeneralUtterances.Cancel)
            .AssertReplyOneOf(allResponseVariations.Cast <string>().ToArray())
            .StartTestAsync();
        }
        public async Task Test_Unhandled_Message()
        {
            var allFirstPromptVariations = AllResponsesTemplates.ExpandTemplate("FirstPromptMessage");
            var allResponseVariations    = AllResponsesTemplates.ExpandTemplate("UnsupportedMessage", TestUserProfileState);

            await GetTestFlow()
            .Send(string.Empty)
            .AssertReplyOneOf(allFirstPromptVariations.Cast <string>().ToArray())
            .Send("Unhandled message")
            .AssertReplyOneOf(allResponseVariations.Cast <string>().ToArray())
            .StartTestAsync();
        }
        /// <summary>
        /// Assert that a new user is greeted with the onboarding prompt.
        /// </summary>
        /// <param name="fromUser">User identifier used for the conversation and activities.</param>
        /// <returns>Task.</returns>
        public async Task Assert_New_User_Greeting(string fromUser)
        {
            var profileState = new UserProfileState {
                Name = TestName
            };

            var allNamePromptVariations  = AllResponsesTemplates.ExpandTemplate("NamePrompt");
            var allHaveMessageVariations = AllResponsesTemplates.ExpandTemplate("HaveNameMessage", profileState);

            var conversation = await StartBotConversationAsync();

            var responses = await SendActivityAsync(conversation, CreateStartConversationEvent(fromUser));

            Assert.AreEqual(1, responses[0].Attachments.Count);
            CollectionAssert.Contains(allNamePromptVariations as ICollection, responses[1].Text);

            responses = await SendActivityAsync(conversation, CreateMessageActivity(fromUser, TestName));

            CollectionAssert.Contains(allHaveMessageVariations as ICollection, responses[2].Text);
        }