/// <summary> /// Starts the execution of the test sequence. /// </summary> /// <remarks>This methods sends the activities from the user to the bot and /// checks the responses from the bot based on the TestActions.</remarks> /// <param name="resourceExplorer">The resource explorer to use.</param> /// <param name="testName">Name of the test.</param> /// <param name="callback">The bot logic.</param> /// <param name="adapter">optional test adapter.</param> /// <param name="middlweare">Middleware to add to the adapter.</param> /// <returns>Runs the exchange between the user and the bot.</returns> public async Task ExecuteAsync(ResourceExplorer resourceExplorer, [CallerMemberName] string testName = null, BotCallbackHandler callback = null, TestAdapter adapter = null, IEnumerable <IMiddleware> middlweare = null) { if (adapter == null) { adapter = DefaultTestAdapter(resourceExplorer, testName, middlweare); } adapter.EnableTrace = EnableTrace; adapter.Locale = Locale; var mockTelemetryClient = new Mock <IBotTelemetryClient>(); adapter.Use(new MockHttpRequestMiddleware(HttpRequestMocks)); adapter.Use(new MockSettingsMiddleware(SettingMocks)); adapter.Use(new TelemetryLoggerMiddleware(mockTelemetryClient.Object, logPersonalInformation: true)); foreach (var userToken in UserTokenMocks) { userToken.Setup(adapter); } async Task Inspect(DialogContextInspector inspector) { var di = new DialogInspector(Dialog, resourceExplorer); var activity = new Activity(); activity.ApplyConversationReference(adapter.Conversation, isIncoming: true); activity.Type = "event"; activity.Name = "inspector"; await adapter.ProcessActivityAsync( activity, async (turnContext, cancellationToken) => await di.InspectAsync(turnContext, inspector).ConfigureAwait(false)).ConfigureAwait(false); } DialogManager dm; if (callback == null) { dm = new DialogManager() .UseResourceExplorer(resourceExplorer) .UseLanguageGeneration(); dm.RootDialog = Dialog; if (LanguagePolicy != null) { dm.UseLanguagePolicy(LanguagePolicy); } callback = dm.OnTurnAsync; } foreach (var testAction in Script) { await testAction.ExecuteAsync(adapter, callback, Inspect).ConfigureAwait(false); } }
/// <summary> /// Starts the execution of the test sequence. /// </summary> /// <remarks>This methods sends the activities from the user to the bot and /// checks the responses from the bot based on the TestActions.</remarks> /// <param name="resourceExplorer">The resource explorer to use.</param> /// <param name="testName">Name of the test.</param> /// <param name="callback">The bot logic.</param> /// <param name="adapter">optional test adapter.</param> /// <param name="languagePolicy">The default language policy.</param> /// <returns>Runs the exchange between the user and the bot.</returns> public async Task ExecuteAsync(ResourceExplorer resourceExplorer, [CallerMemberName] string testName = null, BotCallbackHandler callback = null, TestAdapter adapter = null, LanguagePolicy languagePolicy = null) { if (adapter == null) { adapter = DefaultTestAdapter(resourceExplorer, testName); } adapter.EnableTrace = EnableTrace; adapter.Locale = Locale; adapter.Use(new MockHttpRequestMiddleware(HttpRequestMocks)); foreach (var userToken in UserTokenMocks) { userToken.Setup(adapter); } async Task Inspect(DialogContextInspector inspector) { var di = new DialogInspector(Dialog, resourceExplorer); var activity = new Activity(); activity.ApplyConversationReference(adapter.Conversation, isIncoming: true); activity.Type = "event"; activity.Name = "inspector"; await adapter.ProcessActivityAsync( activity, async (turnContext, cancellationToken) => await di.InspectAsync(turnContext, inspector).ConfigureAwait(false)).ConfigureAwait(false); } if (callback != null) { foreach (var testAction in Script) { await testAction.ExecuteAsync(adapter, callback, Inspect).ConfigureAwait(false); } } else { var dm = new DialogManager(Dialog) .UseResourceExplorer(resourceExplorer) .UseLanguageGeneration(); if (languagePolicy != null) { dm.UseLanguagePolicy(languagePolicy); } foreach (var testAction in Script) { await testAction.ExecuteAsync(adapter, dm.OnTurnAsync, Inspect).ConfigureAwait(false); } } }