设置用于单元测试的UserData

时间:2017-04-05 17:56:31

标签: unit-testing botframework

如何在单元测试的上下文中设置UserData?

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

我应该使用BotData吗?

1 个答案:

答案 0 :(得分:1)

使用&#34; DialogTestBase&#34;来自BotBuilder测试的课程,这对我有用。

        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);