public DeviceStartDialog( List <SkillDialog> skillDialogs, UserState userState) : base(nameof(DeviceStartDialog)) { _skillContextAccessor = userState.CreateProperty <SkillContext>(nameof(SkillContext)); if (skillDialogs == null || skillDialogs.Count == 0) { throw new ArgumentNullException(nameof(skillDialogs)); } todoSkillDialog = skillDialogs.Find(s => s.Id == "toDoSkill"); poiSkillDialog = skillDialogs.Find(s => s.Id == "pointOfInterestSkill"); var waterfall = new WaterfallStep[] { CheckReminder, FindPOI }; AddDialog(todoSkillDialog); AddDialog(poiSkillDialog); AddDialog(new WaterfallDialog("deviceStartDialog", waterfall)); InitialDialogId = "deviceStartDialog"; }
public async Task CancelDialogSendsEoC() { Activity activitySent = null; // Callback to capture the parameters sent to the skill void CaptureAction(string fromBotId, string toBotId, Uri toUri, Uri serviceUrl, string conversationId, Activity activity, CancellationToken cancellationToken) { // Capture values sent to the skill so we can assert the right parameters were used. activitySent = activity; } // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClient = CreateMockSkillClient(CaptureAction); // Use Memory for conversation state var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient); // Create the SkillDialogInstance and the activity to send. var sut = new SkillDialog(dialogOptions); var activityToSend = (Activity)Activity.CreateMessageActivity(); activityToSend.Text = Guid.NewGuid().ToString(); var client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions { Activity = activityToSend }, conversationState: conversationState); // Send something to the dialog to start it await client.SendActivityAsync <IMessageActivity>("irrelevant"); // Cancel the dialog so it sends an EoC to the skill await client.DialogContext.CancelAllDialogsAsync(CancellationToken.None); Assert.AreEqual(ActivityTypes.EndOfConversation, activitySent.Type); }
private static SkillDialog CreateEchoSkillDialog(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, IConfiguration configuration) { var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value; //if (string.IsNullOrWhiteSpace(botId)) //{ // throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not in configuration"); //} var skillHostEndpoint = configuration.GetSection("SkillHostEndpoint")?.Value; if (string.IsNullOrWhiteSpace(skillHostEndpoint)) { throw new ArgumentException("SkillHostEndpoint is not in configuration"); } var skillInfo = configuration.GetSection("EchoSkillInfo").Get <BotFrameworkSkill>() ?? throw new ArgumentException("EchoSkillInfo is not set in configuration"); var skillDialogOptions = new SkillDialogOptions { BotId = botId, ConversationIdFactory = conversationIdFactory, SkillClient = skillClient, SkillHostEndpoint = new Uri(skillHostEndpoint), ConversationState = conversationState, Skill = skillInfo }; var echoSkillDialog = new SkillDialog(skillDialogOptions); return(echoSkillDialog); }
public async Task ShouldNotInterceptOAuthCardsForTokenException() { var connectionName = "connectionName"; var firstResponse = new ExpectedReplies(new List <Activity> { CreateOAuthCardAttachmentActivity("https://test") }); var mockSkillClient = new Mock <BotFrameworkClient>(); mockSkillClient .Setup(x => x.PostActivityAsync <ExpectedReplies>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <Activity>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new InvokeResponse <ExpectedReplies> { Status = 200, Body = firstResponse })); var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient, connectionName); var sut = new SkillDialog(dialogOptions); var activityToSend = CreateSendActivity(); var testAdapter = new TestAdapter(Channels.Test) .Use(new AutoSaveStateMiddleware(conversationState)); var initialDialogOptions = new BeginSkillDialogOptions { Activity = activityToSend }; var client = new DialogTestClient(testAdapter, sut, initialDialogOptions, conversationState: conversationState); testAdapter.ThrowOnExchangeRequest(connectionName, Channels.Test, "user1", "https://test"); var finalActivity = await client.SendActivityAsync <IMessageActivity>("irrelevant"); Assert.IsNotNull(finalActivity); Assert.IsTrue(finalActivity.Attachments.Count == 1); }
public async Task ShouldHandleInvokeActivities() { Activity activitySent = null; string fromBotIdSent = null; string toBotIdSent = null; Uri toUriSent = null; // Callback to capture the parameters sent to the skill void CaptureAction(string fromBotId, string toBotId, Uri toUri, Uri serviceUrl, string conversationId, Activity activity, CancellationToken cancellationToken) { // Capture values sent to the skill so we can assert the right parameters were used. fromBotIdSent = fromBotId; toBotIdSent = toBotId; toUriSent = toUri; activitySent = activity; } // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClient = CreateMockSkillClient(CaptureAction); // Use Memory for conversation state var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient); // Create the SkillDialogInstance and the activity to send. var activityToSend = (Activity)Activity.CreateInvokeActivity(); activityToSend.Name = Guid.NewGuid().ToString(); var sut = new SkillDialog(dialogOptions); var client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions { Activity = activityToSend }, conversationState: conversationState); // Send something to the dialog to start it await client.SendActivityAsync <Activity>("irrelevant"); // Assert results and data sent to the SkillClient for fist turn Assert.AreEqual(dialogOptions.BotId, fromBotIdSent); Assert.AreEqual(dialogOptions.Skill.AppId, toBotIdSent); Assert.AreEqual(dialogOptions.Skill.SkillEndpoint.ToString(), toUriSent.ToString()); Assert.AreEqual(activityToSend.Name, activitySent.Name); Assert.AreEqual(DeliveryModes.ExpectReplies, activitySent.DeliveryMode); Assert.AreEqual(DialogTurnStatus.Waiting, client.DialogTurnResult.Status); // Send a second message to continue the dialog await client.SendActivityAsync <Activity>("Second message"); // Assert results for second turn Assert.AreEqual("Second message", activitySent.Text); Assert.AreEqual(DialogTurnStatus.Waiting, client.DialogTurnResult.Status); // Send EndOfConversation to the dialog await client.SendActivityAsync <IEndOfConversationActivity>((Activity)Activity.CreateEndOfConversationActivity()); // Assert we are done. Assert.AreEqual(DialogTurnStatus.Complete, client.DialogTurnResult.Status); }
public async Task BeginDialogOptionsValidation() { var dialogOptions = new SkillDialogOptions(); var sut = new SkillDialog(dialogOptions); var client = new DialogTestClient(Channels.Test, sut); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant"), "null options should fail"); client = new DialogTestClient(Channels.Test, sut, new Dictionary <string, string>()); await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant"), "options should be of type DialogArgs"); client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions()); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant"), "Activity in DialogArgs should be set"); }
public async Task EndOfConversationFromExpectRepliesCallsDeleteConversationReferenceAsync() { Activity activitySent = null; // Callback to capture the parameters sent to the skill void CaptureAction(string fromBotId, string toBotId, Uri toUri, Uri serviceUrl, string conversationId, Activity activity, CancellationToken cancellationToken) { // Capture values sent to the skill so we can assert the right parameters were used. activitySent = activity; } // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClientx = CreateMockSkillClient(CaptureAction); var eoc = Activity.CreateEndOfConversationActivity() as Activity; var expectedReplies = new List <Activity>(); expectedReplies.Add(eoc); // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClient = CreateMockSkillClient(CaptureAction, expectedReplies: expectedReplies); // Use Memory for conversation state var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient); // Create the SkillDialogInstance and the activity to send. var sut = new SkillDialog(dialogOptions); var activityToSend = (Activity)Activity.CreateMessageActivity(); activityToSend.DeliveryMode = DeliveryModes.ExpectReplies; activityToSend.Text = Guid.NewGuid().ToString(); var client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions { Activity = activityToSend }, conversationState: conversationState); // Send something to the dialog to start it await client.SendActivityAsync <IMessageActivity>("hello"); Assert.Empty((dialogOptions.ConversationIdFactory as SimpleConversationIdFactory).ConversationRefs); Assert.Equal(1, (dialogOptions.ConversationIdFactory as SimpleConversationIdFactory).CreateCount); }
public async Task ShouldThrowHttpExceptionOnPostFailure() { // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClient = CreateMockSkillClient(null, 500); // Use Memory for conversation state var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient); // Create the SkillDialogInstance and the activity to send. var sut = new SkillDialog(dialogOptions); var activityToSend = (Activity)Activity.CreateMessageActivity(); activityToSend.Text = Guid.NewGuid().ToString(); var client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions { Activity = activityToSend }, conversationState: conversationState); // Send something to the dialog await Assert.ThrowsExceptionAsync <HttpRequestException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant")); }