|
12 | 12 | using Microsoft.Bot.Connector.Authentication; |
13 | 13 | using Microsoft.Bot.Schema; |
14 | 14 | using Microsoft.Bot.Schema.Teams; |
| 15 | +using Moq; |
15 | 16 | using Newtonsoft.Json.Linq; |
16 | 17 | using Xunit; |
17 | 18 |
|
@@ -51,6 +52,61 @@ public async Task TestSendMessageToTeamsChannelAsync() |
51 | 52 | await handler.OnTurnAsync(turnContext); |
52 | 53 | } |
53 | 54 |
|
| 55 | + [Fact] |
| 56 | + public async Task TestSendMessageToTeamsChannel2Async() |
| 57 | + { |
| 58 | + // Arrange |
| 59 | + |
| 60 | + var expectedTeamsChannelId = "teams-channel-id"; |
| 61 | + var expectedAppId = "app-id"; |
| 62 | + var expectedServiceUrl = "service-url"; |
| 63 | + var expectedActivityId = "activity-id"; |
| 64 | + var expectedConversationId = "conversation-id"; |
| 65 | + |
| 66 | + var requestActivity = new Activity { ServiceUrl = expectedServiceUrl }; |
| 67 | + |
| 68 | + var adapter = new TestCreateConversationAdapter(expectedActivityId, expectedConversationId); |
| 69 | + |
| 70 | + var turnContextMock = new Mock<ITurnContext>(); |
| 71 | + turnContextMock.Setup(tc => tc.Activity).Returns(requestActivity); |
| 72 | + turnContextMock.Setup(tc => tc.Adapter).Returns(adapter); |
| 73 | + |
| 74 | + var activity = new Activity |
| 75 | + { |
| 76 | + Type = "message", |
| 77 | + Text = "Test-SendMessageToTeamsChannelAsync", |
| 78 | + ChannelId = Channels.Msteams, |
| 79 | + ChannelData = new TeamsChannelData |
| 80 | + { |
| 81 | + Team = new TeamInfo |
| 82 | + { |
| 83 | + Id = "team-id", |
| 84 | + }, |
| 85 | + }, |
| 86 | + }; |
| 87 | + |
| 88 | + // Act |
| 89 | + |
| 90 | + var r = await TeamsInfo.SendMessageToTeamsChannelAsync(turnContextMock.Object, activity, expectedTeamsChannelId, expectedAppId, CancellationToken.None); |
| 91 | + |
| 92 | + // Assert |
| 93 | + |
| 94 | + Assert.Equal(expectedConversationId, r.Item1.Conversation.Id); |
| 95 | + Assert.Equal(expectedActivityId, r.Item2); |
| 96 | + Assert.Equal(expectedAppId, adapter.AppId); |
| 97 | + Assert.Equal(Channels.Msteams, adapter.ChannelId); |
| 98 | + Assert.Equal(expectedServiceUrl, adapter.ServiceUrl); |
| 99 | + Assert.Null(adapter.Audience); |
| 100 | + |
| 101 | + var channelData = adapter.ConversationParameters.ChannelData; |
| 102 | + |
| 103 | + var channel = channelData.GetType().GetProperty("channel").GetValue(channelData, null); |
| 104 | + var id = channel.GetType().GetProperty("id").GetValue(channel, null); |
| 105 | + |
| 106 | + Assert.Equal(expectedTeamsChannelId, id); |
| 107 | + Assert.Equal(adapter.ConversationParameters.Activity, activity); |
| 108 | + } |
| 109 | + |
54 | 110 | [Fact] |
55 | 111 | public async Task TestGetMeetingInfoAsync() |
56 | 112 | { |
@@ -586,5 +642,60 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques |
586 | 642 | return Task.FromResult(response); |
587 | 643 | } |
588 | 644 | } |
| 645 | + |
| 646 | + private class TestCreateConversationAdapter : BotAdapter |
| 647 | + { |
| 648 | + private string _activityId; |
| 649 | + |
| 650 | + private string _conversationId; |
| 651 | + |
| 652 | + public TestCreateConversationAdapter(string activityId, string conversationId) |
| 653 | + { |
| 654 | + _activityId = activityId; |
| 655 | + _conversationId = conversationId; |
| 656 | + } |
| 657 | + |
| 658 | + public string AppId { get; set; } |
| 659 | + |
| 660 | + public string ChannelId { get; set; } |
| 661 | + |
| 662 | + public string ServiceUrl { get; set; } |
| 663 | + |
| 664 | + public string Audience { get; set; } |
| 665 | + |
| 666 | + public ConversationParameters ConversationParameters { get; set; } |
| 667 | + |
| 668 | + public override Task CreateConversationAsync(string botAppId, string channelId, string serviceUrl, string audience, ConversationParameters conversationParameters, BotCallbackHandler callback, CancellationToken cancellationToken) |
| 669 | + { |
| 670 | + AppId = botAppId; |
| 671 | + ChannelId = channelId; |
| 672 | + ServiceUrl = serviceUrl; |
| 673 | + Audience = audience; |
| 674 | + ConversationParameters = conversationParameters; |
| 675 | + |
| 676 | + var activity = new Activity { Id = _activityId, Conversation = new ConversationAccount { Id = _conversationId } }; |
| 677 | + |
| 678 | + var mockTurnContext = new Mock<ITurnContext>(); |
| 679 | + mockTurnContext.Setup(tc => tc.Activity).Returns(activity); |
| 680 | + |
| 681 | + callback(mockTurnContext.Object, cancellationToken); |
| 682 | + return Task.CompletedTask; |
| 683 | + } |
| 684 | + |
| 685 | + public override Task DeleteActivityAsync(ITurnContext turnContext, ConversationReference reference, CancellationToken cancellationToken) |
| 686 | + { |
| 687 | + throw new NotImplementedException(); |
| 688 | + } |
| 689 | + |
| 690 | + public override Task<ResourceResponse[]> SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken) |
| 691 | + { |
| 692 | + throw new NotImplementedException(); |
| 693 | + } |
| 694 | + |
| 695 | + public override Task<ResourceResponse> UpdateActivityAsync(ITurnContext turnContext, Activity activity, CancellationToken cancellationToken) |
| 696 | + { |
| 697 | + throw new NotImplementedException(); |
| 698 | + } |
| 699 | + } |
589 | 700 | } |
590 | 701 | } |
0 commit comments