问题
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