简体   繁体   English

如何为需要用户进行身份验证的Bot Framework v4对话框编写单元测试?

[英]How to write unit tests for a Bot Framework v4 Dialog that requires the user to authenticate?

I'm writing Unit Tests (C#) for Dialogs created with version 4 of the MS Bot Framework. 我正在为使用MS Bot Framework第4版创建的Dialog编写单元测试(C#)。 I'm wondering how to unit test a ComponentDialog containing a WaterfallDialog and a OAuthPrompt where one step of the WaterfallDialog requires the user to login using the OAuthprompt? 我想知道如何对包含WaterfallDialog和OAuthPrompt的ComponentDialog进行单元测试,其中WaterfallDialog的一个步骤要求用户使用OAuthprompt登录?

When I write a Unit Test for such a Dialog using the TestAdapter and TestFlow I get to following exception: 当我使用TestAdapter和TestFlow为这样的Dialog编写单元测试时,我得到以下异常:

OAuthPrompt.GetUserToken(): not supported by the current adapter

This makes sense because the TestAdapter doesn't have a GetUserTokenAsync method like the BotFrameworkAdapter has (this method it called from OAuthPrompt.GetUserToken). 这是有道理的,因为TestAdapter没有像BotFrameworkAdapter那样的GetUserTokenAsync方法(这个方法是从OAuthPrompt.GetUserToken调用的)。

How can we work around this? 我们如何解决这个问题?

The blunt, honest answer is that this will be extremely difficult to factor properly for unit testing today without making a large investment in working around the limitations of the APIs today. 坦率,诚实的答案是,如果不对今天的API局限性进行大量投资,今天对于单元测试来说,这将是非常困难的。

As you pointed out in this specific case OAuthPrompt has strong ties to the ITurnContext::Adapter property being an instance of BotFrameworkAdapter specifically. 当你在这种特殊情况下指出OAuthPrompt具有的紧密联系ITurnContext::Adapter属性为实例BotFrameworkAdapter明确。 This alone is "not good", but coupled with the fact that you can't actually override the APIs on BotFrameworkAdapter that the OAuthPrompt actually needs to call means you're completely stuck unless you use an advanced faking framework that allows for replacing non-virtual members. 仅此一点“不好”,但结合以下事实:您实际上无法覆盖BotFrameworkAdapter上的OAuthPrompt实际需要调用的API意味着您完全陷入困境,除非您使用允许替换非的高级伪造框架虚拟成员。

Honestly, having looked into this for a bit, I don't think you can work around this right now. 老实说,考虑到这一点,我认为你现在不能解决这个问题。 I would implore you to raise this an issue in the botbuilder-dotnet repo on GitHub and I will gladly chime in there with a recommendation to the team on how they could go about fixing this. 我想恳请你在GitHub上的botbuilder-dotnet repo中提出这个问题,我很乐意在那里向团队提出建议,告诉他们如何解决这个问题。

UPDATE 8/15/2019 更新8/15/2019

Since the original answer, this was refactored to introduce an IUserTokenProvider interface which the OAuthPrompt now checks to see if the current ITurnContext::Adapter supports and, if so, calls through to its implementation. 从最初的答案开始,这被重构为引入一个IUserTokenProvider接口, OAuthPrompt现在检查该接口以查看当前的ITurnContext::Adapter支持,如果支持,则调用其实现。 This means you can now mock this interface and implement the proper scenarios for tests. 这意味着您现在可以模拟此接口并实现适当的测试场景。

有一个很好的Channel 9系列可以解决这个问题,你可以在这里看到: https//channel9.msdn.com/Series/DevOps-for-the-Bot-Framework/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的对话框不等待 Bot Framework v4 中的用户响应 - My dialog does not wait for user response in Bot Framework v4 如何在 bot 框架 v4 中将对话框设置为欢迎消息 - how to set a dialog as the welcome message in bot framework v4 如何在 Bot Framework V4 中对提示验证器进行单元测试 - How to unit test a prompt validator in Bot Framework V4 Bot Framework v4圆形对话框参考 - Bot framework v4 circular dialog reference 如何使用 Microsoft Bot Framework SDK v4 从专用租户中的聊天机器人向 MS Teams 进行身份验证? - How to authenticate to MS Teams from a chatbot in a dedicated tenant with Microsoft Bot Framework SDK v4? Ms Bot 虚拟助手 bot 框架 V4 中的用户头像 - User Avatar in Ms Bot virtual Assistant bot framework V4 使用 TestFlow 时如何将选项传递给对话框 - Azure botframework v4 - C# - 单元测试 - How to pass in options to a Dialog when using TestFlow - Azure botframework v4 - C# - Unit Tests 在瀑布对话框中使用 luis 验证提示(Bot 框架 V4) - Validate prompt with luis in waterfall dialog (Bot framework V4) 如何从机器人框架 v4 中的 ActivityHandler.OnMessageActivityAsync 启动瀑布对话框 - How to start a waterfall dialog from ActivityHandler.OnMessageActivityAsync in bot framework v4 如何在C#[Bot Framework v4]中从QnaBot(qna制造商api)调用瀑布对话框? - How to call waterfall dialog from QnaBot (qna maker api) in C# [Bot Framework v4]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM