microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/test/Microsoft.Teams.Bot.Core.Tests/CompatConversationClientTests.cs
154lines · 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.Teams.Bot.Compat; |
| 12 | using Microsoft.Teams.Bot.Core; |
| 13 | using Xunit.Abstractions; |
| 14 | |
| 15 | namespace Microsoft.Bot.Core.Tests |
| 16 | { |
| 17 | public class CompatConversationClientTests |
| 18 | { |
| 19 | private readonly ITestOutputHelper _outputHelper; |
| 20 | private readonly string _serviceUrl = "https://smba.trafficmanager.net/amer/"; |
| 21 | private readonly string _userId; |
| 22 | private readonly string _conversationId; |
| 23 | private readonly string _agenticAppBlueprintId; |
| 24 | private readonly string? _agenticAppId; |
| 25 | private readonly string? _agenticUserId; |
| 26 | |
| 27 | public CompatConversationClientTests(ITestOutputHelper outputHelper) |
| 28 | { |
| 29 | _outputHelper = outputHelper; |
| 30 | _userId = Environment.GetEnvironmentVariable("TEST_USER_ID") ?? throw new InvalidOperationException("TEST_USER_ID environment variable not set"); |
| 31 | _conversationId = Environment.GetEnvironmentVariable("TEST_CONVERSATIONID") ?? throw new InvalidOperationException("TEST_ConversationId environment variable not set"); |
| 32 | |
| 33 | _agenticAppBlueprintId = Environment.GetEnvironmentVariable("AzureAd__ClientId") ?? throw new InvalidOperationException("AzureAd__ClientId environment variable not set"); |
| 34 | _agenticAppId = Environment.GetEnvironmentVariable("TEST_AGENTIC_APPID");// ?? throw new InvalidOperationException("TEST_AGENTIC_APPID environment variable not set"); |
| 35 | _agenticUserId = Environment.GetEnvironmentVariable("TEST_AGENTIC_USERID");// ?? throw new InvalidOperationException("TEST_AGENTIC_USERID environment variable not set"); |
| 36 | } |
| 37 | |
| 38 | [Fact(Skip = "not implemented")] |
| 39 | public async Task GetMemberAsync() |
| 40 | { |
| 41 | |
| 42 | var compatAdapter = InitializeCompatAdapter(); |
| 43 | ConversationReference conversationReference = new ConversationReference |
| 44 | |
| 45 | { |
| 46 | ChannelId = "msteams", |
| 47 | ServiceUrl = _serviceUrl, |
| 48 | Conversation = new ConversationAccount |
| 49 | { |
| 50 | Id = _conversationId |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | await compatAdapter.ContinueConversationAsync( |
| 55 | string.Empty, conversationReference, |
| 56 | async (turnContext, cancellationToken) => |
| 57 | { |
| 58 | TeamsChannelAccount member = await TeamsInfo.GetMemberAsync(turnContext, _userId, cancellationToken: cancellationToken); |
| 59 | Assert.NotNull(member); |
| 60 | Assert.Equal(_userId, member.Id); |
| 61 | |
| 62 | }, CancellationToken.None); |
| 63 | } |
| 64 | |
| 65 | [Fact] |
| 66 | public async Task GetPagedMembersAsync() |
| 67 | { |
| 68 | |
| 69 | var compatAdapter = InitializeCompatAdapter(); |
| 70 | ConversationReference conversationReference = new ConversationReference |
| 71 | |
| 72 | { |
| 73 | ChannelId = "msteams", |
| 74 | ServiceUrl = _serviceUrl, |
| 75 | Conversation = new ConversationAccount() |
| 76 | { |
| 77 | Id = _conversationId |
| 78 | }, |
| 79 | User = new ChannelAccount() |
| 80 | { |
| 81 | Id = "28:fake-bot-id", |
| 82 | Properties = |
| 83 | { |
| 84 | ["agenticAppId"] = _agenticAppId, |
| 85 | ["agenticUserId"] = _agenticUserId, |
| 86 | ["agenticAppBlueprintId"] = _agenticAppBlueprintId |
| 87 | } |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | await compatAdapter.ContinueConversationAsync( |
| 92 | string.Empty, conversationReference, |
| 93 | async (turnContext, cancellationToken) => |
| 94 | { |
| 95 | var result = await CompatTeamsInfo.GetPagedMembersAsync(turnContext, cancellationToken: cancellationToken); |
| 96 | Assert.NotNull(result); |
| 97 | Assert.True(result.Members.Count > 0); |
| 98 | var m0 = result.Members[0]; |
| 99 | Assert.Equal(_userId, m0.Id); |
| 100 | |
| 101 | }, CancellationToken.None); |
| 102 | } |
| 103 | |
| 104 | [Fact(Skip = "not implemented")] |
| 105 | public async Task GetMeetingInfo() |
| 106 | { |
| 107 | string meetingId = Environment.GetEnvironmentVariable("TEST_MEETINGID") ?? throw new InvalidOperationException("TEST_MEETINGID environment variable not set"); |
| 108 | var compatAdapter = InitializeCompatAdapter(); |
| 109 | ConversationReference conversationReference = new ConversationReference |
| 110 | |
| 111 | { |
| 112 | ChannelId = "msteams", |
| 113 | ServiceUrl = _serviceUrl, |
| 114 | Conversation = new ConversationAccount |
| 115 | { |
| 116 | Id = _conversationId |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | await compatAdapter.ContinueConversationAsync( |
| 121 | string.Empty, conversationReference, |
| 122 | async (turnContext, cancellationToken) => |
| 123 | { |
| 124 | var result = await TeamsInfo.GetMeetingInfoAsync(turnContext, meetingId, cancellationToken); |
| 125 | Assert.NotNull(result); |
| 126 | |
| 127 | }, CancellationToken.None); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | CompatAdapter InitializeCompatAdapter() |
| 132 | { |
| 133 | IConfigurationBuilder builder = new ConfigurationBuilder() |
| 134 | .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) |
| 135 | .AddEnvironmentVariables(); |
| 136 | |
| 137 | IConfiguration configuration = builder.Build(); |
| 138 | |
| 139 | ServiceCollection services = new(); |
| 140 | services.AddSingleton(configuration); |
| 141 | services.AddCompatAdapter(); |
| 142 | services.AddLogging((builder) => { |
| 143 | builder.AddXUnit(_outputHelper); |
| 144 | builder.AddFilter("System.Net", LogLevel.Warning); |
| 145 | builder.AddFilter("Microsoft.Identity", LogLevel.Error); |
| 146 | builder.AddFilter("Microsoft.Teams", LogLevel.Information); |
| 147 | }); |
| 148 | |
| 149 | var serviceProvider = services.BuildServiceProvider(); |
| 150 | CompatAdapter compatAdapter = (CompatAdapter)serviceProvider.GetRequiredService<IBotFrameworkHttpAdapter>(); |
| 151 | return compatAdapter; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |