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(); }
public void AttachmentPromptWithNullIdShouldFail() { var nullId = ""; nullId = null; var attachmentPrompt = new AttachmentPrompt(nullId); }
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(); }
public async Task BasicAttachmentPrompt() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter(TestAdapter.CreateConversation(nameof(BasicAttachmentPrompt))) .Use(new AutoSaveStateMiddleware(convoState)) .Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false))); // Create new DialogSet. var dialogs = new DialogSet(dialogState); // Create and add attachment prompt to DialogSet. var attachmentPrompt = new AttachmentPrompt("AttachmentPrompt"); dialogs.Add(attachmentPrompt); // Create mock attachment for testing. var attachment = new Attachment { Content = "some content", ContentType = "text/plain" }; // Create incoming activity with attachment. var activityWithAttachment = new Activity { Type = ActivityTypes.Message, Attachments = new List <Attachment> { attachment } }; await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(); if (results.Status == DialogTurnStatus.Empty) { var options = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "please add an attachment." } }; await dc.PromptAsync("AttachmentPrompt", options, cancellationToken); } else if (results.Status == DialogTurnStatus.Complete) { var attachments = results.Result as List <Attachment>; var content = MessageFactory.Text((string)attachments[0].Content); await turnContext.SendActivityAsync(content, cancellationToken); } }) .Send("hello") .AssertReply("please add an attachment.") .Send(activityWithAttachment) .AssertReply("some content") .StartTestAsync(); }
public async Task BasicAttachmentPrompt() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(convoState); // Create new DialogSet. var dialogs = new DialogSet(dialogState); // Create and add attachment prompt to DialogSet. var attachmentPrompt = new AttachmentPrompt("AttachmentPrompt"); dialogs.Add(attachmentPrompt); // Create mock attachment for testing. var attachment = new Attachment { Content = "some content", ContentType = "text/plain" }; // Create incoming activity with attachment. var activityWithAttachment = new Activity { Type = ActivityTypes.Message, Attachments = new List <Attachment> { attachment } }; await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext); var results = await dc.ContinueAsync(); if (!turnContext.Responded && !results.HasActive && !results.HasResult) { var options = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "please add an attachment." } }; await dc.PromptAsync("AttachmentPrompt", options); } else if (!results.HasActive && results.HasResult) { var attachments = results.Result as List <Attachment>; var content = (string)attachments[0].Content; await turnContext.SendActivityAsync(content); } }) .Send("hello") .AssertReply("please add an attachment.") .Send(activityWithAttachment) .AssertReply("some content") .StartTestAsync(); }
public async Task AttachmentPrompt_ShouldSendPrompt() { await new TestFlow(new TestAdapter(), async(context) => { var attachmentPrompt = new AttachmentPrompt(); await attachmentPrompt.Prompt(context, "please add an attachment."); }) .Send("hello") .AssertReply("please add an attachment.") .StartTest(); }
public async Task AttachmentPrompt_ShouldRecognizeAttachment() { var adapter = new TestAdapter() .Use(new ConversationState <TestState>(new MemoryStorage())); var attachment = new Attachment { Content = "some content", ContentType = "text/plain" }; var activityWithAttachment = MessageFactory.Attachment(attachment); await new TestFlow(adapter, async(context) => { var state = ConversationState <TestState> .Get(context); var attachmentPrompt = new AttachmentPrompt(); if (!state.InPrompt) { state.InPrompt = true; await attachmentPrompt.Prompt(context, "please add an attachment."); } else { var attachmentResult = await attachmentPrompt.Recognize(context); if (attachmentResult.Succeeded()) { var reply = (string)attachmentResult.Attachments.First().Content; await context.SendActivity(reply); } else { await context.SendActivity(attachmentResult.Status.ToString()); } } }) .Send("hello") .AssertReply("please add an attachment.") .Send(activityWithAttachment) .AssertReply("some content") .StartTest(); }
public void AttachmentPromptWithEmptyIdShouldFail() { var emptyId = ""; var attachmentPrompt = new AttachmentPrompt(emptyId); }