我如何在c#中为Microsoft Bot Framework V4编写一个简单的单元测试用例,因为它现在使用.netcore

问题描述 投票:2回答:1

我必须为BotFramework V4简单的echo方法编写单元测试用例。但是我找不到模拟机器人的方法。其实我不知道从哪里开始。我已经阅读了所有可以在Google上找到的与之相关的文档,但是都没有在代码级别上进行解释。一个具体的例子将有很大帮助。

  [TestMethod]
    public async Task CreatingAGoodContact()
    {
        var convoState = new ConversationState(new MemoryStorage());

        var adapter = new TestAdapter()
            .Use(new AutoSaveStateMiddleware(convoState));

        var dialogState = convoState.CreateProperty<DialogState> 
                  ("dialogState");

        var dialogs = new DialogSet(dialogState);
        dialogs.Add(CreateWaterfall());

        await new TestFlow(adapter, async (turnContext, 
               cancellationToken) =>
        {
            var dc = await dialogs.CreateContextAsync(turnContext, 
                cancellationToken);

            // await dc.ContinueDialogAsync(cancellationToken);
            if (!turnContext.Responded)
            {
                await dc.BeginDialogAsync("test-waterfall", null, 
                cancellationToken);
            }

        })
        .Send("Say something to start test")
        .AssertReply("What is their first name?")
       }
botframework vs-unit-testing-framework
1个回答
0
投票

您需要调用.StartTestAsync()才能开始执行测试

© www.soinside.com 2019 - 2024. All rights reserved.