Exemplo n.º 1
0
        public async Task Prueba_deberia_devolver_respuestaAsync()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var waitCalled      = false;
                var message         = string.Empty;
                var postAsyncCalled = false;

                var target = new RootDialog();

                var activity = new Activity(ActivityTypes.Message)
                {
                    Text = "Hello World"
                };

                var awaiter = new Microsoft.Bot.Builder.Internals.Fibers.Fakes.StubIAwaiter <IMessageActivity>()
                {
                    IsCompletedGet = () => true,
                    GetResult      = () => activity
                };

                var awaitable = new Microsoft.Bot.Builder.Dialogs.Fakes.StubIAwaitable <IMessageActivity>()
                {
                    GetAwaiter = () => awaiter
                };

                var context = new Microsoft.Bot.Builder.Dialogs.Fakes.StubIDialogContext();

                Microsoft.Bot.Builder.Dialogs.Fakes.ShimExtensions.PostAsyncIBotToUserStringStringCancellationToken = (user, s1, s2, token) =>
                {
                    message         = s1;
                    postAsyncCalled = true;
                    return(Task.CompletedTask);
                };

                Microsoft.Bot.Builder.Dialogs.Fakes.ShimExtensions.WaitIDialogStackResumeAfterOfIMessageActivity = (stack, callback) =>
                {
                    if (waitCalled)
                    {
                        return;
                    }

                    waitCalled = true;

                    // The callback is what is being tested.
                    callback(context, awaitable);
                };

                // Act
                await target.StartAsync(context);

                // Assert
                Assert.AreEqual("You sent Hello World which was 11 characters", message, "Message is wrong");
                Assert.IsTrue(postAsyncCalled, "PostAsync was not called");
            }
        }
Exemplo n.º 2
0
        public async Task Bot_Test_Attachments()
        {
            foreach (var item in RootDialog.dataAtt)
            {
                var preg = item.Key;
                var att  = item.Value;

                using (ShimsContext.Create())
                {
                    var waitCalled           = false;
                    IMessageActivity message = null;

                    var target = new RootDialog();

                    var activity = new Activity(ActivityTypes.Message)
                    {
                        Text         = preg,
                        From         = new ChannelAccount("id", "name"),
                        Recipient    = new ChannelAccount("recipid", "recipname"),
                        Conversation = new ConversationAccount(false, "id", "name")
                    };

                    var awaiter = new Microsoft.Bot.Builder.Internals.Fibers.Fakes.StubIAwaiter <IMessageActivity>()
                    {
                        IsCompletedGet = () => true,
                        GetResult      = () => activity
                    };

                    var awaitable = new Microsoft.Bot.Builder.Dialogs.Fakes.StubIAwaitable <IMessageActivity>()
                    {
                        GetAwaiter = () => awaiter
                    };

                    var context = new Microsoft.Bot.Builder.Dialogs.Fakes.StubIDialogContext();

                    context.PostAsyncIMessageActivityCancellationToken = (messageActivity, token) => {
                        message = messageActivity;
                        return(Task.CompletedTask);
                    };

                    Microsoft.Bot.Builder.Dialogs.Fakes.ShimExtensions.WaitIDialogStackResumeAfterOfIMessageActivity = (stack, callback) =>
                    {
                        if (waitCalled)
                        {
                            return;
                        }
                        waitCalled = true;
                        callback(context, awaitable);
                    };
                    await target.MessageReceivedWithTextAsync(context, awaitable);


                    Assert.AreEqual(att, message.Attachments[0]);
                }
            }
        }
Exemplo n.º 3
0
        public async Task TestShouldReturnErrorIfEmptyOrSpaces()
        {
            List <string> strings = new List <string>()
            {
                "", "      ", null
            };

            foreach (var item in strings)
            {
                var preg = item;

                using (ShimsContext.Create())
                {
                    // Arrange
                    var waitCalled           = false;
                    IMessageActivity message = null;

                    var target = new RootDialog();

                    var activity = new Activity(ActivityTypes.Message)
                    {
                        Text         = preg,
                        From         = new ChannelAccount("id", "name"),
                        Recipient    = new ChannelAccount("recipid", "recipname"),
                        Conversation = new ConversationAccount(false, "id", "name")
                    };

                    var awaiter = new Microsoft.Bot.Builder.Internals.Fibers.Fakes.StubIAwaiter <IMessageActivity>()
                    {
                        IsCompletedGet = () => true,
                        GetResult      = () => activity
                    };

                    var awaitable = new Microsoft.Bot.Builder.Dialogs.Fakes.StubIAwaitable <IMessageActivity>()
                    {
                        GetAwaiter = () => awaiter
                    };

                    var context = new Microsoft.Bot.Builder.Dialogs.Fakes.StubIDialogContext();
                    context.PostAsyncIMessageActivityCancellationToken = (messageActivity, token) => {
                        message = messageActivity;
                        return(Task.CompletedTask);
                    };


                    Microsoft.Bot.Builder.Dialogs.Fakes.ShimExtensions.WaitIDialogStackResumeAfterOfIMessageActivity = (stack, callback) =>
                    {
                        if (waitCalled)
                        {
                            return;
                        }

                        waitCalled = true;

                        // The callback is what is being tested.
                        callback(context, awaitable);
                    };

                    // Act
                    //await target.StartAsync(context);
                    await target.MessageReceivedWithTextAsync(context, awaitable);

                    // Assert
                    Assert.AreEqual(message.Text, errorMessage);
                }
            }
        }