Exemplo n.º 1
0
        public async Task AttachmentPrompt()
        {
            var activities   = TranscriptUtilities.GetFromTestContext(TestContext);
            var convState    = new ConversationState(new MemoryStorage());
            var testProperty = convState.CreateProperty <Dictionary <string, object> >("test");

            var adapter = new TestAdapter()
                          .Use(convState);

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    var state  = await testProperty.GetAsync(turnContext, () => new Dictionary <string, object>());
                    var prompt = new AttachmentPrompt();

                    var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                    if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                    {
                        await prompt.BeginAsync(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();
        }
Exemplo n.º 2
0
        public async Task BasicAttachmentPrompt()
        {
            ConversationState convoState = new ConversationState(new MemoryStorage());
            var testProperty             = convoState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>());

            TestAdapter adapter = new TestAdapter()
                                  .Use(convoState);

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

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var state  = await testProperty.GetAsync(turnContext);
                var prompt = new AttachmentPrompt();

                var dialogCompletion = await prompt.ContinueAsync(turnContext, state);
                if (!dialogCompletion.IsActive && !dialogCompletion.IsCompleted)
                {
                    await prompt.BeginAsync(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);
                }
            })
            .Send("hello")
            .AssertReply("please add an attachment.")
            .Send(activityWithAttachment)
            .AssertReply("some content")
            .StartTestAsync();
        }