forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DialogAndWelcomeBotTests.cs
56 lines (49 loc) · 2.07 KB
/
DialogAndWelcomeBotTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.BotBuilderSamples.Bots;
using Xunit;
using CoreBot.Tests.Common;
namespace CoreBot.Tests.Bots
{
public class DialogAndWelcomeBotTests
{
[Fact]
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);
}
}
}