public async Task ReturnsWelcomeCardOnConversationUpdate()
        {
            // Arrange
            var mockRootDialog = SimpleMockFactory.CreateMockDialog <Dialog>(null, "mockRootDialog");
            var memoryStorage  = new MemoryStorage();
            var sut            = new DialogAndWelcomeBot <Dialog>(new ConversationState(memoryStorage), new UserState(memoryStorage), mockRootDialog.Object, null);

            // Create conversationUpdate activity
            var conversationUpdateActivity = new Activity
            {
                Type         = ActivityTypes.ConversationUpdate,
                MembersAdded = new List <ChannelAccount>
                {
                    new ChannelAccount {
                        Id = "theUser"
                    },
                },
                Recipient = new ChannelAccount {
                    Id = "theBot"
                },
            };
            var testAdapter = new TestAdapter(Channels.Test);

            // Act
            // Send the conversation update activity to the bot.
            await testAdapter.ProcessActivityAsync(conversationUpdateActivity, sut.OnTurnAsync, CancellationToken.None);

            // Assert we got the welcome card
            var reply = (IMessageActivity)testAdapter.GetNextReply();

            Assert.Equal(1, reply.Attachments.Count);
            Assert.Equal("application/vnd.microsoft.card.adaptive", reply.Attachments.FirstOrDefault()?.ContentType);

            // Assert that we started the main dialog.
            reply = (IMessageActivity)testAdapter.GetNextReply();
            Assert.Equal("Dialog mock invoked", reply.Text);
        }
Exemple #2
0
        public async Task ShouldUseCustomChannelId(string targetChannel)
        {
            var sut = new TestAdapter(targetChannel);

            var receivedChannelId = string.Empty;

            async Task TestCallback(ITurnContext context, CancellationToken token)
            {
                receivedChannelId = context.Activity.ChannelId;
                await context.SendActivityAsync("test reply from the bot", cancellationToken : token);
            }

            await sut.SendTextToBotAsync("test message", TestCallback, CancellationToken.None);

            var reply = sut.GetNextReply();

            Assert.Equal(targetChannel, receivedChannelId);
            Assert.Equal(targetChannel, reply.ChannelId);
        }
 /// <summary>
 /// Gets and returns the next bot response./>.
 /// </summary>
 /// <returns>The next activity in the queue; or null, if the queue is empty.</returns>
 /// <typeparam name="T">An <see cref="IActivity"/> derived type.</typeparam>
 public virtual T GetNextReply <T>()
     where T : IActivity
 {
     return((T)_testAdapter.GetNextReply());
 }