c# - 如何将Adaptive Card填写的数据传回TestFlow和TestAdapter进行测试?

标签 c# testing botframework

带有 TestFlow 和 Adapter 的 Enterprise Bot Template 上提供了一些测试工具。

我们能否使用 TestFlow 提交测试数据,就好像它已在自适应卡中填充并提交回机器人以测试来自 TestMethod 的响应?不是文本,而是填写好的回复。

enter image description here

方法如下,注释放在适当的操作位置。

[TestMethod]
public async Task TestSoftwareIssue()
{
    string response = "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(response)
        .Send("software")
        // .AssertReply("")
        .AssertReply(activity => CheckAttachment(activity.AsMessageActivity()))
        // How to send a Adaptive Card filled out message back?
        .StartTestAsync();
}

这里还有自适应卡片的简化版本。

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "TextBlock",
            "text": "Email"
        },
        {
            "type": "Input.Text",
            "id": "Email",
            "placeholder": "name@example.com"
        },
        {
            "type": "TextBlock",
            "text": "Summary"
        },
        {
            "type": "Input.Text",
            "id": "Summary",
            "placeholder": "Please describe the issue",
            "isMultiline": true
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit",
            "data": {
                "form": "Ticket"
            }
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0"
}

最佳答案

只是一个更新。 我已经成功地实现了这样的工作。

这是一个示例测试,其中 responseOne 是一个 json 格式的字符串,它保存 accessForm.json 中数据字段的键值对

[TestMethod]
public async Task TestFormProcess()
// ...
await GetTestFlow()
    .Send(GeneralUtterances.Access)
    .AssertReply(activity => CheckAttachment(activity.AsMessageActivity(), @".\Resources\TestForms\accessForm.json"))
    .Send(CreateReply(responseOne))
    .AssertReply("Some reply")
    .StartTestAsync();
public IActivity CreateReply(string json)
        {
            return new Activity()
            {
                Value = JsonConvert.DeserializeObject(file),
            };
        }

关于c# - 如何将Adaptive Card填写的数据传回TestFlow和TestAdapter进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55945561/

相关文章:

c# - 防止 UI 在处理数据时卡住

spring - 如何将来自规则的值注入(inject)测试 Spring 上下文?

android - 使用 SugarORM 和 Robolectric 进行测试

javascript - 如何在bot框架版本4 javascript中使用cardImage接口(interface)的tap属性

c# - 在 dynamodb 中使用 context.fromquery 查询时限制不起作用

c# - 具有流畅验证集合的自定义消息

c# - 你如何在消息事件异步中检测事件对话框

.net - 机器人对话框不等待

c# - Automapper 有时无法映射通过 ForMember 设置的属性

unit-testing - 有没有办法用 Mockito 在 Dart 中只模拟对象的一部分?