コード例 #1
0
ファイル: PromptTests.cs プロジェクト: wballard/BotBuilder
        public async Task PromptFailureAsync <T>(Action <IDialogContext, ResumeAfter <T> > prompt)
        {
            var dialogRoot = MockDialog <T>();

            dialogRoot
            .Setup(d => d.StartAsync(It.IsAny <IDialogContext>()))
            .Returns <IDialogContext>(async c => { c.Wait(dialogRoot.Object.FirstMessage); });
            dialogRoot
            .Setup(d => d.FirstMessage(It.IsAny <IDialogContext>(), It.IsAny <IAwaitable <Connector.Message> >()))
            .Returns <IDialogContext, IAwaitable <object> >(async(c, a) => { prompt(c, dialogRoot.Object.PromptResult); });

            var conversationID = NewID();
            var botToUser      = new BotToUserQueue(new Message()
            {
                ConversationId = conversationID
            });
            var context = await MakeContextAsync(dialogRoot.Object, botToUser);

            IUserToBot userToBot = context;
            {
                var toBot = new Connector.Message()
                {
                    ConversationId = conversationID
                };
                botToUser.Clear();
                await userToBot.SendAsync(toBot);

                var toUser = botToUser.Messages.Single();
                Assert.AreEqual(PromptText, toUser.Text);
            }
            {
                var toBot = new Connector.Message()
                {
                    ConversationId = conversationID
                };
                botToUser.Clear();
                await userToBot.SendAsync(toBot);

                var toUser = botToUser.Messages.Single();
                Assert.AreEqual(RetryText, toUser.Text);
            }

            {
                var toBot = new Connector.Message()
                {
                    ConversationId = conversationID
                };
                botToUser.Clear();
                await userToBot.SendAsync(toBot);

                var toUser = botToUser.Messages.Single();
                dialogRoot.Verify(d => d.PromptResult(context, It.Is <IAwaitable <T> >(actual => actual.ToTask().IsFaulted)), Times.Once);
            }
        }
コード例 #2
0
        public async Task <Connector.Message> Post([FromBody] Connector.Message toBot, CancellationToken token)
        {
            using (var scope = DialogModule.BeginLifetimeScope(Container.Instance, toBot))
            {
                // construct the authentication url
                var builder = new UriBuilder(this.Request.GetEncodedUrl());
                builder.Path = $"/api/account/";
                var uri = builder.Uri;

                // make the authentication url and the client keys available to root dialog if needed
                // somewhat hacky - would be better done by uniting Autofac and ASP.NET DI containers
                scope.Resolve <Uri>(TypedParameter.From(uri));
                scope.Resolve <IClientKeys>(TypedParameter.From(this.keys));

                // post the message to the bot
                var task = scope.Resolve <IPostToBot>();
                await task.PostAsync(toBot, token);

                // return the last message to the connector
                var botToUser = scope.Resolve <SendLastInline_BotToUser>();
                return(botToUser.ToUser);
            }
        }