已经在bot的企业模板4.2.2中编写了一些测试,到目前为止,该模板对于基于文本的响应非常有效。但是,当流程涉及自适应卡时,是否有办法访问附件以确保一切正常?
在此对话框中,选择软件后,将发送回自适应卡。 从客户端看起来像这样。 https://imgur.com/a/aEDwFYl
[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();
}
关于如何验证自适应卡输出的任何建议都是很好的。
我认为需要某种方式来访问从发送给用户的bot的活动附件,这在确定如何立即执行此操作时会遇到一些麻烦。
谢谢!
答案 0 :(得分:0)
因此,在进行了一些探索之后,找到了一种方法来解决此问题,该方法是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)
然后我们可以创建我们自己的验证函数,该函数可以处理断言。
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());
}
然后[TestMethod]可以像这样工作。
[TestMethod]
public async Task TestSoftwareIssue()
{
await GetTestFlow()
.Send(GeneralUtterances.GeneralIssue)
.AssertReply("Some Response")
.Send("Some Choice")
// .AssertReply("")
.AssertReply(activity => CheckAttachment(activity.AsMessageActivity()))
.StartTestAsync();
}