microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/test/Microsoft.Teams.Bot.Core.Tests/CompatConversationClientTests.cs
127lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Bot.Builder.Integration.AspNet.Core; |
| 5 | using Microsoft.Bot.Builder.Teams; |
| 6 | using Microsoft.Bot.Schema; |
| 7 | using Microsoft.Bot.Schema.Teams; |
| 8 | using Microsoft.Extensions.Configuration; |
| 9 | using Microsoft.Extensions.DependencyInjection; |
| 10 | using Microsoft.Extensions.Logging; |
| 11 | using Microsoft.Extensions.Logging.Abstractions; |
| 12 | using Microsoft.Teams.Bot.Compat; |
| 13 | using Microsoft.Teams.Bot.Core; |
| 14 | |
| 15 | namespace Microsoft.Bot.Core.Tests |
| 16 | { |
| 17 | public class CompatConversationClientTests |
| 18 | { |
| 19 | string serviceUrl = "https://smba.trafficmanager.net/amer/"; |
| 20 | |
| 21 | string userId = Environment.GetEnvironmentVariable("TEST_USER_ID") ?? throw new InvalidOperationException("TEST_USER_ID environment variable not set"); |
| 22 | string conversationId = Environment.GetEnvironmentVariable("TEST_CONVERSATIONID") ?? throw new InvalidOperationException("TEST_ConversationId environment variable not set"); |
| 23 | |
| 24 | [Fact(Skip = "not implemented")] |
| 25 | public async Task GetMemberAsync() |
| 26 | { |
| 27 | |
| 28 | var compatAdapter = InitializeCompatAdapter(); |
| 29 | ConversationReference conversationReference = new ConversationReference |
| 30 | |
| 31 | { |
| 32 | ChannelId = "msteams", |
| 33 | ServiceUrl = serviceUrl, |
| 34 | Conversation = new ConversationAccount |
| 35 | { |
| 36 | Id = conversationId |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | await compatAdapter.ContinueConversationAsync( |
| 41 | string.Empty, conversationReference, |
| 42 | async (turnContext, cancellationToken) => |
| 43 | { |
| 44 | TeamsChannelAccount member = await TeamsInfo.GetMemberAsync(turnContext, userId, cancellationToken: cancellationToken); |
| 45 | Assert.NotNull(member); |
| 46 | Assert.Equal(userId, member.Id); |
| 47 | |
| 48 | }, CancellationToken.None); |
| 49 | } |
| 50 | |
| 51 | [Fact] |
| 52 | public async Task GetPagedMembersAsync() |
| 53 | { |
| 54 | |
| 55 | var compatAdapter = InitializeCompatAdapter(); |
| 56 | ConversationReference conversationReference = new ConversationReference |
| 57 | |
| 58 | { |
| 59 | ChannelId = "msteams", |
| 60 | ServiceUrl = serviceUrl, |
| 61 | Conversation = new ConversationAccount |
| 62 | { |
| 63 | Id = conversationId |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | await compatAdapter.ContinueConversationAsync( |
| 68 | string.Empty, conversationReference, |
| 69 | async (turnContext, cancellationToken) => |
| 70 | { |
| 71 | var result = await TeamsInfo.GetPagedMembersAsync(turnContext, cancellationToken: cancellationToken); |
| 72 | Assert.NotNull(result); |
| 73 | Assert.True(result.Members.Count > 0); |
| 74 | var m0 = result.Members[0]; |
| 75 | Assert.Equal(userId, m0.Id); |
| 76 | |
| 77 | }, CancellationToken.None); |
| 78 | } |
| 79 | |
| 80 | [Fact(Skip = "not implemented")] |
| 81 | public async Task GetMeetingInfo() |
| 82 | { |
| 83 | string meetingId = Environment.GetEnvironmentVariable("TEST_MEETINGID") ?? throw new InvalidOperationException("TEST_MEETINGID environment variable not set"); |
| 84 | var compatAdapter = InitializeCompatAdapter(); |
| 85 | ConversationReference conversationReference = new ConversationReference |
| 86 | |
| 87 | { |
| 88 | ChannelId = "msteams", |
| 89 | ServiceUrl = serviceUrl, |
| 90 | Conversation = new ConversationAccount |
| 91 | { |
| 92 | Id = conversationId |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | await compatAdapter.ContinueConversationAsync( |
| 97 | string.Empty, conversationReference, |
| 98 | async (turnContext, cancellationToken) => |
| 99 | { |
| 100 | var result = await TeamsInfo.GetMeetingInfoAsync(turnContext, meetingId, cancellationToken); |
| 101 | Assert.NotNull(result); |
| 102 | |
| 103 | }, CancellationToken.None); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | CompatAdapter InitializeCompatAdapter() |
| 108 | { |
| 109 | IConfigurationBuilder builder = new ConfigurationBuilder() |
| 110 | .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) |
| 111 | .AddEnvironmentVariables(); |
| 112 | |
| 113 | IConfiguration configuration = builder.Build(); |
| 114 | |
| 115 | ServiceCollection services = new(); |
| 116 | services.AddSingleton<ILogger<BotApplication>>(NullLogger<BotApplication>.Instance); |
| 117 | services.AddSingleton<ILogger<ConversationClient>>(NullLogger<ConversationClient>.Instance); |
| 118 | services.AddSingleton(configuration); |
| 119 | services.AddCompatAdapter(); |
| 120 | services.AddLogging(configure => configure.AddConsole()); |
| 121 | |
| 122 | var serviceProvider = services.BuildServiceProvider(); |
| 123 | CompatAdapter compatAdapter = (CompatAdapter)serviceProvider.GetRequiredService<IBotFrameworkHttpAdapter>(); |
| 124 | return compatAdapter; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |