Reputation: 131
Have been writing some tests in the enterprise template 4.2.2 of the bot which has is working great for text based responses so far. However when the flow involves Adaptive Cards, is there a way to access the attachments to make sure everything works as intended?
In this dialog, when software is selected, an adaptive card is sent back. Looks like this from the client side. https://i.sstatic.net/WeHFR.jpg
[TestMethod]
public async Task TestSoftwareIssue()
{
string resp = "What sort of issue do you have?\n\n" +
" 1. Computer\n" +
" 2. Software\n" +
" 3. Insuffient Permissions for Access\n" +
" 4. Account expired\n" +
" 5. Other";
await GetTestFlow()
.Send(GeneralUtterances.GeneralIssue)
.AssertReply(resp)
.Send("software")
// Check attachment somehow?
.AssertReply("")
.StartTestAsync();
}
Any advice on how the output of adaptive cards can be verified would be great.
I think there needs to be some way to access the activity attachments from the bot sent to the user, having some trouble determining how this could be done right now.
Thanks!
Upvotes: 1
Views: 632
Reputation: 131
So after some exploring, figured one way to work this out with this function which is part of TestFlow.
/// <param name="validateActivity">A validation method to apply to an activity from the bot.
/// This activity should throw an exception if validation fails.</param>
public TestFlow AssertReply(Action<IActivity> validateActivity, [CallerMemberName] string description = null, uint timeout = 3000)
Then we can create our own verification function which can handle assertions.
public void CheckAttachment(IMessageActivity messageActivity)
{
// Check if content is the same
var messageAttachment = messageActivity.Attachments.First();
// Example attachment
var adaptiveCardJson = File.ReadAllText(@".\Resources\TicketForm.json");
var expected = new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCardJson),
};
Assert.AreEqual(messageAttachment.Content.ToString(), expected.Content.ToString());
}
The [TestMethod] can then work something like this.
[TestMethod]
public async Task TestSoftwareIssue()
{
await GetTestFlow()
.Send(GeneralUtterances.GeneralIssue)
.AssertReply("Some Response")
.Send("Some Choice")
// .AssertReply("")
.AssertReply(activity => CheckAttachment(activity.AsMessageActivity()))
.StartTestAsync();
}
Upvotes: 1