title: How to unit test custom prompt that requires user select a choice in Bot Framework
body: <p>I have some custom prompts made with adaptive cards which require user inputs such as input.ChoiceSet and input.Text.</p>
  <p>My problem here is if I have a card with 3 choices ('Red', 'Blue', 'Green'), and I would like to test the result of &quot;Red&quot; 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.</p>
  <p>I use JObject to get the user's selection as a string;</p>
  <p>In the constructor of my dialog class I have add the prompt to the dialog.</p>
  <pre class="lang-cs prettyprint-override"><code>AddDialog(new CustomPrompt(&quot;cardPrompt&quot;, DialogValidators.AdaptiveCardValidatorAsync));
  
  </code></pre>
  <p>Here is my dialog code for testing.</p>
  <pre class="lang-cs prettyprint-override"><code>private async Task&lt;DialogTurnResult&gt; aStep(WaterfallStepContext stepContext, CancellationToken cancellationToken)
  {
              var adaptiveActivity = stepContext.Context.Activity.CreateReply();
              adaptiveActivity.AddCardAttachment();
              return await stepContext.PromptAsync(
                  &quot;CardPrompt&quot;,
                  new PromptOptions
                  {
                      Prompt = adaptiveActivity,
                      RetryPrompt = MessageFactory.Text(&quot;xxx&quot;),
                      Validations = new List&lt;string&gt; { &quot;selectionCard&quot; }
                  });
  }
  
  private async Task&lt;DialogTurnResult&gt; bStep(WaterfallStepContext stepContext, CancellationToken cancellationToken)
  {
              JObject answerObject = (JObject)JsonConvert.DeserializeObject(stepContext.Result.ToString());
              string userChoice = answerObject[&quot;choiceID&quot;].ToString();
  }
  
  </code></pre>
  <p>Below is my test code.</p>
  <pre class="lang-cs prettyprint-override"><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&lt;IMessageActivity&gt;(&quot;Red&quot;);
  Assert.AreEqual(XXXX, reply....);
  </code></pre>
  <p>How to work with DialogTestClient for the test?</p>
  <p>Appreciate your time for this.</p>
  <p><strong>Update</strong></p>
  <p>Below is my prompt class. It extends Prompt2 which has abstract methods (OnPromptAsync and OnRecognizeAsync) and extends Dialog class.</p>
  <pre class="lang-cs prettyprint-override"><code>
  public class CustomPrompt : Prompt2&lt;string&gt;
      {
          public CustomPrompt(string dialogId, PromptValidator&lt;string&gt; validator = null)
              : base(dialogId, validator)
          {
          }
  
          protected async override Task OnPromptAsync(ITurnContext turnContext, IDictionary&lt;string, object&gt; state, PromptOptions options, bool isRetry, CancellationToken cancellationToken = default(CancellationToken))
          {
              if (turnContext == null)
              {
                  throw new ArgumentNullException(nameof(turnContext));
              }
  
              if (options == null)
              {
                  throw new ArgumentNullException(nameof(options));
              }
  
              if (isRetry &amp;&amp; options.RetryPrompt != null)
              {
                  await turnContext.SendActivityAsync(options.RetryPrompt, cancellationToken).ConfigureAwait(false);
              }
              else if (options.Prompt != null)
              {
                  await turnContext.SendActivityAsync(options.Prompt, cancellationToken).ConfigureAwait(false);
              }
          }
  
          protected override Task&lt;PromptRecognizerResult&lt;string&gt;&gt; OnRecognizeAsync(ITurnContext turnContext, IDictionary&lt;string, object&gt; state, PromptOptions options, CancellationToken cancellationToken = default(CancellationToken))
          {
              if (turnContext == null)
              {
                  throw new ArgumentNullException(nameof(turnContext));
              }
  
              var result = new PromptRecognizerResult&lt;string&gt;();
              if (turnContext.Activity.Type == ActivityTypes.Message)
              {
                  var message = turnContext.Activity.AsMessageActivity();
                  if (!string.IsNullOrEmpty(message.Text))
                  {
                      result.Succeeded = true;
                      result.Value = message.Text;
                  }
  
                  /*Add handling for Value from adaptive card*/
                  else if (message.Value != null)
                  {
                      result.Succeeded = true;
                      result.Value = message.Value.ToString();
                  }
              }
  
              return Task.FromResult(result);
          }
      }
  
  
  </code></pre>
  <p>Here is the structure of my card.</p>
  <pre class="lang-none prettyprint-override"><code>{
    &quot;type&quot;: &quot;AdaptiveCard&quot;,
    &quot;body&quot;: [
      {
        &quot;type&quot;: &quot;Container&quot;,
        &quot;items&quot;: [
          {
            &quot;type&quot;: &quot;Input.ChoiceSet&quot;,
            &quot;wrap&quot;:  true,
            &quot;id&quot;: &quot;choiceID&quot;,
            &quot;value&quot;: {defaultValue}
            &quot;placeholder&quot;: &quot;Placeholder text&quot;,
            &quot;choices&quot;: [
              {
                title: &quot;aaaa&quot;,
                value: &quot;testChoice&quot;
              }
            ],
            &quot;style&quot;: &quot;expanded&quot;
          }
        ]
      }
    ],
    &quot;actions&quot;: [
      {
        &quot;type&quot;: &quot;Action.Submit&quot;,
        &quot;id&quot;: &quot;submit&quot;,
        &quot;title&quot;: &quot;Confirm&quot;,
        &quot;data&quot;: {
          &quot;value&quot;: &quot;submit&quot;,
          &quot;id&quot;: selectionCard&quot;
        }
      },
      {
        &quot;type&quot;: &quot;Action.Submit&quot;,
        &quot;id&quot;: &quot;cancel&quot;,
        &quot;title&quot;: &quot;Cancel&quot;,
        &quot;data&quot;: {
          &quot;value&quot;: &quot;cancel&quot;,
          &quot;id&quot;: &quot;selectionCard&quot;
        }
      }
    ],
    &quot;$schema&quot;: &quot;http://adaptivecards.io/schemas/adaptive-card.json&quot;,
    &quot;version&quot;: &quot;1.1&quot;
  </code></pre>
  <p>I was wondering how do I test if I select any choice of the card and get proper response from the bot using TestFlow.
  Thanks.</p>