且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设置UserData以进行单元测试

更新时间:2023-02-20 20:56:09

使用了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);