我正在尝试对包含2个步骤的对话框进行单元测试。第一步,我在stepContext中设置一个值,第二步,我试图从上下文中访问该值。但是在单元测试中,该值在上下文中不可用。我正在使用DialogtestClient类进行单元测试。 https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.testing.dialogtestclient?view=botbuilder-dotnet-stable
这是我的testDialog.cs
private void InitializeWaterfallDialog() { // Create Waterfall Steps var waterfallSteps = new WaterfallStep[] { this.DisplayStepAsync, this.HandleClickedStepAsync, }; // Add Named Dialogs this.AddDialog(new WaterfallDialog(nameof(ModalityDialog), waterfallSteps)); this.AddDialog(new TextPrompt(nameof(TextPrompt))); // Set the starting Dialog this.InitialDialogId = nameof(ModalityDialog); } private async Task<DialogTurnResult> DisplayStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { stepContext.Values["abc"] = "def"; } private async Task<DialogTurnResult> HandleClickedStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var selected = stepContext.Values["abc"]; }
单元测试我正在使用DialogTestClient对对话框进行单元测试。
[TestMethod]
public async Task DialogSuccess()
{
// Arrange
var testClient = new DialogTestClient(Channels.Test, this.testDialog);
// Act
var reply = await testClient.SendActivityAsync<IMessageActivity>
(string.Empty).ConfigureAwait(false);
Activity activity = new Activity() { Text = "abc" };
await testClient.SendActivityAsync<IMessageActivity>(activity).ConfigureAwait(false);
}
使用DialogtestClient发送第一个活动时,将调用Dialog的第一步并设置上下文值。然后,当我发送第二个活动时,将调用Dialog的第二个步骤,
找到stepContext.Values [“ abc”] = null
。 有什么办法可以让我获得
stepContext.Values [“ abc”] =“ def”
在单元测试中第二次发送活动时?
我们将不胜感激。TIA。