本文介绍了设置UserData以进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在上下文中设置UserData以进行单元测试?

How do i setup the UserData within the context for unit testing?

        var context = new Mock<IDialogContext>();
        context.Setup(c => c.Activity).Returns(() => new Activity());
        context.Setup(c => c.UserData).Returns(() => ?);

我应该使用BotData吗?

Should i use BotData?

推荐答案

使用了BotBuilder测试中的"DialogTestBase"类,它对我有用.

Used the "DialogTestBase" class from BotBuilder tests and this worked for me.

        IBotDataBag dataBag;
        var container = Build(Options.LastWriteWinsCachingBotDataStore);
        var msg = MakeTestMessage();
        using (var scope = DialogModule.BeginLifetimeScope(container, msg))
        {
            var botData = scope.Resolve<IBotData>();
            await botData.LoadAsync(default(CancellationToken));
            dataBag = scope.Resolve<Func<IBotDataBag>>()();
        }

        var context = new Mock<IDialogContext>();
        context.Setup(c => c.UserData).Returns(() => dataBag);
        context.Object.UserData.SetValue(AppConstants.HelpType, helpType);

这篇关于设置UserData以进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 23:28