public SurveyTests() { var userProfileAccessor = new Mock <IStatePropertyAccessor <UserProfile> >(); var userProfile = new UserProfile(); userProfileAccessor.Setup(x => x.GetAsync(It.IsAny <ITurnContext>(), It.IsAny <Func <UserProfile> >(), It.IsAny <CancellationToken>())).ReturnsAsync(userProfile); var surveyState = new SurveyState(); _features = new Features { CollateResponses = true, RealisticTypingDelay = false }; var botSettings = new BotSettings(); _feedbackServiceMock = new Mock <IFeedbackService>(); _feedbackBotStateMock = new Mock <IFeedbackBotStateRepository>(); _feedbackBotStateMock.SetupGet(x => x.UserProfile).Returns(userProfileAccessor.Object); var dialogFactory = new DialogFactory(new List <IComponentBuilder <ComponentDialog> > { new FreeTextDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings)), new MultipleChoiceDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings), _feedbackServiceMock.Object), new SurveyStartDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings)), new SurveyEndDialogComponentBuilder(_feedbackBotStateMock.Object, Options.Create(_features), Options.Create(botSettings), _feedbackServiceMock.Object) }); _dialog = dialogFactory.Create <SurveyDialog>(new InMemoryApprenticeFeedbackSurveyV6()); }
public override object Load(JToken obj, JsonSerializer serializer, Type type) { ComponentDialog dialog = base.Load(obj, serializer, type) as ComponentDialog; // Dialogs are not a public property of ComponentDialog so we read the dialog // collection from the json and call AddDialog() on each dialog. if (dialog != null) { var dialogs = obj["dialogs"]; // If there are dialogs, load them. if (dialogs != null) { if (obj["dialogs"].Type != JTokenType.Array) { throw new JsonSerializationException("Expected array property \"dialogs\" in ComponentDialog"); } foreach (var dialogJObj in dialogs) { var innerDialog = dialogJObj.ToObject <Dialog>(serializer); dialog.AddDialog(innerDialog); } } } return(dialog); }
public IComponentDialogResult ShowDialog() { _componentDialog = new ComponentDialog(); bool?result = _componentDialog.ShowDialog(); if (result == true) { return(new ComponentDialogResult(_componentDialog.SelectedComponentType)); } return(null); }
private ComponentDialog CreateDialogStep(ISurveyStepDefinition stepDefinition) { try { var stepBuilder = this.stepBuilders.First(s => s.Matches(stepDefinition)); ComponentDialog step = stepBuilder.Create(stepDefinition); return(step); } catch (Exception ex) { throw new DialogFactoryException($"Could not create ComponentDialog : Unsupported type [{stepDefinition.GetType().FullName}]"); } }
public async Task DialogSet_AddTelemetrySet_OnCyclicalDialogStructures() { var convoState = new ConversationState(new MemoryStorage()); var dialogStateProperty = convoState.CreateProperty <DialogState>("dialogstate"); var component1 = new ComponentDialog("component1"); var component2 = new ComponentDialog("component2"); component1.Dialogs.Add(component2); component2.Dialogs.Add(component1); // Without the check in DialogSet setter, this test throws StackOverflowException. component1.Dialogs.TelemetryClient = new MyBotTelemetryClient(); await Task.CompletedTask; }
public async Task WaterfallStepParentIsWaterfallParent() { var convoState = new ConversationState(new MemoryStorage()); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var dialogs = new DialogSet(dialogState); const string WATERFALL_PARENT_ID = "waterfall-parent-test-dialog"; var waterfallParent = new ComponentDialog(WATERFALL_PARENT_ID); var steps = new WaterfallStep[] { async(step, cancellationToken) => { Assert.AreEqual(step.Parent.ActiveDialog.Id, waterfallParent.Id); await step.Context.SendActivityAsync("verified"); return(Dialog.EndOfTurn); } }; waterfallParent.AddDialog(new WaterfallDialog( "test", steps)); waterfallParent.InitialDialogId = "test"; dialogs.Add(waterfallParent); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); await dc.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded) { await dc.BeginDialogAsync(WATERFALL_PARENT_ID, null, cancellationToken); } }) .Send("hello") .AssertReply("verified") .StartTestAsync(); }
public async Task DialogManager_UserState_NestedDialogs_PersistedAcrossConversations() { var firstConversationId = Guid.NewGuid().ToString(); var secondConversationId = Guid.NewGuid().ToString(); var storage = new MemoryStorage(); var outerAdaptiveDialog = CreateTestDialog("user.name"); var componentDialog = new ComponentDialog(); componentDialog.AddDialog(outerAdaptiveDialog); await CreateFlow(componentDialog, storage, firstConversationId) .Send("hi") .AssertReply("Hello, what is your name?") .Send("Carlos") .AssertReply("Hello Carlos, nice to meet you!") .StartTestAsync(); await CreateFlow(componentDialog, storage, secondConversationId) .Send("hi") .AssertReply("Hello Carlos, nice to meet you!") .StartTestAsync(); }
public async Task CallDialogDefinedInParentComponent() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(convoState)); var options = new Dictionary <string, string> { { "value", "test" } }; var childComponent = new ComponentDialog("childComponent"); var childSteps = new WaterfallStep[] { async(step, ct) => { await step.Context.SendActivityAsync("Child started."); return(await step.BeginDialogAsync("parentDialog", options)); }, async(step, ct) => { Assert.AreEqual("test", (string)step.Result); await step.Context.SendActivityAsync("Child finished."); return(await step.EndDialogAsync()); }, }; childComponent.AddDialog(new WaterfallDialog( "childDialog", childSteps)); var parentComponent = new ComponentDialog("parentComponent"); parentComponent.AddDialog(childComponent); var parentSteps = new WaterfallStep[] { async(step, dc) => { var stepOptions = step.Options as IDictionary <string, string>; Assert.IsNotNull(stepOptions); Assert.IsTrue(stepOptions.ContainsKey("value")); await step.Context.SendActivityAsync($"Parent called with: {stepOptions["value"]}"); return(await step.EndDialogAsync(stepOptions["value"])); }, }; parentComponent.AddDialog(new WaterfallDialog( "parentDialog", parentSteps)); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dialogs = new DialogSet(dialogState); dialogs.Add(parentComponent); var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(cancellationToken); if (results.Status == DialogTurnStatus.Empty) { await dc.BeginDialogAsync("parentComponent", null, cancellationToken); } else if (results.Status == DialogTurnStatus.Complete) { var value = (int)results.Result; await turnContext.SendActivityAsync(MessageFactory.Text("Done"), cancellationToken); } }) .Send("Hi") .AssertReply("Child started.") .AssertReply("Parent called with: test") .AssertReply("Child finished.") .StartTestAsync(); }
public async Task CallDialogInParentComponent() { var convoState = new ConversationState(new MemoryStorage()); var dialogState = convoState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName)) .Use(new AutoSaveStateMiddleware(convoState)) .Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false))); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var state = await dialogState.GetAsync(turnContext, () => new DialogState()); var dialogs = new DialogSet(dialogState); var childComponent = new ComponentDialog("childComponent"); var childStep = new WaterfallStep[] { async(step, token) => { await step.Context.SendActivityAsync("Child started."); return(await step.BeginDialogAsync("parentDialog", "test")); }, async(step, token) => { await step.Context.SendActivityAsync($"Child finished. Value: {step.Result}"); return(await step.EndDialogAsync()); } }; childComponent.AddDialog(new WaterfallDialog("childDialog", childStep)); var parentComponent = new ComponentDialog("parentComponent"); parentComponent.AddDialog(childComponent); var parentStep = new WaterfallStep[] { async(step, token) => { await step.Context.SendActivityAsync("Parent called."); return(await step.EndDialogAsync(step.Options)); } }; parentComponent.AddDialog(new WaterfallDialog("parentDialog", parentStep)); dialogs.Add(parentComponent); var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(cancellationToken); if (results.Status == DialogTurnStatus.Empty) { await dc.BeginDialogAsync("parentComponent", null, cancellationToken); } else if (results.Status == DialogTurnStatus.Complete) { var value = (int)results.Result; await turnContext.SendActivityAsync(MessageFactory.Text($"Bot received the number '{value}'."), cancellationToken); } }) .Send("Hi") .AssertReply("Child started.") .AssertReply("Parent called.") .AssertReply("Child finished. Value: test") .StartTestAsync(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FigureSettingClick(object sender, EventArgs e) { // Get setting PPathwayObject obj = (PPathwayObject)m_con.Canvas.FocusNode; ComponentSetting cs = obj.Setting.Clone(); cs.Name = m_con.ComponentManager.GetRandomKey(); cs.IsDefault = false; // Show Setting Dialog. ComponentDialog dlg = new ComponentDialog(m_con.ComponentManager); using (dlg) { dlg.IsPathway = true; dlg.Setting = cs; if (dlg.ShowDialog() != DialogResult.OK) return; dlg.ApplyChange(); cs = dlg.Setting; cs.IsStencil = false; m_con.ComponentManager.RegisterSetting(cs); m_con.SetNodeIcons(); // Register new stencil if (dlg.DoesRegister) { m_con.Stencil.AddStencil(cs); } } // Update. List<PPathwayObject> list = new List<PPathwayObject>(); foreach (PPathwayObject pObj in m_con.Canvas.SelectedNodes) { if (!pObj.Setting.Type.Equals(cs.Type)) continue; pObj.Setting = cs; list.Add(pObj); } m_con.NotifyDataChanged(list); }
private void propertyToolStripMenuItem_Click(object sender, System.EventArgs e) { if (m_stencil == null) return; // Show Setting Dialog. ComponentDialog dlg = new ComponentDialog(m_con.ComponentManager); dlg.Setting = m_stencil.Setting; using (dlg) { if (dlg.ShowDialog() != DialogResult.OK) return; dlg.ApplyChange(); m_con.SetNodeIcons(); } }