Exemplo n.º 1
0
        public async Task AttachmentPrompt()
        {
            var activities = TranscriptUtilities.GetFromTestContext(TestContext);

            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new AttachmentPrompt();

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "please add an attachment."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var attachmentResult = (AttachmentResult)dialogCompletion.Result;
                    var reply            = (string)attachmentResult.Attachments.First().Content;
                    await turnContext.SendActivityAsync(reply);
                }
            })
            .Test(activities)
            .StartTestAsync();
        }
        public async Task BasicAttachmentPrompt()
        {
            TestAdapter adapter = new TestAdapter()
                                  .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage()));

            var attachment = new Attachment {
                Content = "some content", ContentType = "text/plain"
            };
            var activityWithAttachment = MessageFactory.Attachment(attachment);

            await new TestFlow(adapter, async(turnContext) =>
            {
                var state  = ConversationState <Dictionary <string, object> > .Get(turnContext);
                var prompt = new AttachmentPrompt();

                var dialogCompletion = await prompt.Continue(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.Begin(turnContext, state, new PromptOptions {
                        PromptString = "please add an attachment."
                    });
                }
                else if (dialogCompletion.IsCompleted)
                {
                    var attachmentResult = (AttachmentResult)dialogCompletion.Result;
                    var reply            = (string)attachmentResult.Attachments.First().Content;
                    await turnContext.SendActivity(reply);
                }
            })
            .Send("hello")
            .AssertReply("please add an attachment.")
            .Send(activityWithAttachment)
            .AssertReply("some content")
            .StartTest();
        }