How to unit test custom prompt that requires user select a choice in Bot Framework

被刻印的时光 ゝ 提交于 2020-12-15 06:42:53

问题


I have some custom prompts made with adaptive cards which require user inputs such as input.ChoiceSet and input.Text.

My problem here is if I have a card with 3 choices ('Red', 'Blue', 'Green'), and I would like to test the result of "Red" being selected. How do I send the choice and get result in my test code. I would like to unit test the result and flow after something is selected and the user hit the submit button.

Here is my dialog code for testing.

private async Task<DialogTurnResult> XXXXXXXX(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
            var adaptiveActivity = stepContext.Context.Activity.CreateReply();
            adaptiveActivity.AddCardAttachment();
            return await stepContext.PromptAsync(
                "CardPrompt",
                new PromptOptions
                {
                    Prompt = adaptiveActivity,
                    RetryPrompt = MessageFactory.Text("xxx"),
                    Validations = new List<string> { "Card" }
                });
}

Below is my test code.

userState = new UserState(new MemoryStorage());
var subDialog = new SubDialog(userState);
var MainDialog = new MainDialog(subDialog);
var testClient = new DialogTestClient(Channels.Msteams, MainDialog);

// some code here

reply = await testClient.SendActivityAsync<IMessageActivity>("Red");
Assert.AreEqual(XXXX, reply....);

How to work with DialogTestClient for the test?

Appreciate your time for this.

来源:https://stackoverflow.com/questions/65151720/how-to-unit-test-custom-prompt-that-requires-user-select-a-choice-in-bot-framewo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!