microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
samples/migration-bot

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/test/Microsoft.Teams.Bot.Core.Tests/TeamsApiFacadeTests.cs

643lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Bot.Connector;
5using Microsoft.Teams.Bot.Core;
6using Microsoft.Teams.Bot.Core.Hosting;
7using Microsoft.Teams.Bot.Core.Schema;
8using Microsoft.Extensions.Configuration;
9using Microsoft.Extensions.DependencyInjection;
10using Microsoft.Extensions.Logging;
11using Microsoft.Teams.Bot.Apps;
12using Microsoft.Teams.Bot.Apps.Api;
13using Microsoft.Teams.Bot.Apps.Schema;
14using Xunit.Abstractions;
15
16namespace Microsoft.Bot.Core.Tests;
17
18/// <summary>
19/// Integration tests for the TeamsApi facade.
20/// These tests verify that the hierarchical API facade correctly delegates to underlying clients.
21/// </summary>
22public class TeamsApiFacadeTests
23{
24 private readonly ServiceProvider _serviceProvider;
25 private readonly TeamsBotApplication _teamsBotApplication;
26 private readonly Uri _serviceUrl;
27 private readonly string _conversationId;
28 private readonly ConversationAccount _recipient = new ConversationAccount();
29 private readonly AgenticIdentity? _agenticIdentity;
30
31 public TeamsApiFacadeTests(ITestOutputHelper outputHelper)
32 {
33 IConfigurationBuilder builder = new ConfigurationBuilder()
34 .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
35 .AddEnvironmentVariables();
36
37 IConfiguration configuration = builder.Build();
38
39 ServiceCollection services = new();
40 services.AddLogging((builder) => {
41 builder.AddXUnit(outputHelper);
42 builder.AddFilter("System.Net", LogLevel.Warning);
43 builder.AddFilter("Microsoft.Identity", LogLevel.Error);
44 builder.AddFilter("Microsoft.Teams", LogLevel.Information);
45 });
46 services.AddSingleton(configuration);
47 services.AddHttpContextAccessor();
48 services.AddTeamsBotApplication();
49 _serviceProvider = services.BuildServiceProvider();
50 _teamsBotApplication = _serviceProvider.GetRequiredService<TeamsBotApplication>();
51 _serviceUrl = new Uri(Environment.GetEnvironmentVariable("TEST_SERVICEURL") ?? "https://smba.trafficmanager.net/teams/");
52 _conversationId = Environment.GetEnvironmentVariable("TEST_CONVERSATIONID") ?? throw new InvalidOperationException("TEST_ConversationId environment variable not set");
53 string agenticAppBlueprintId = Environment.GetEnvironmentVariable("AzureAd__ClientId") ?? throw new InvalidOperationException("AzureAd__ClientId environment variable not set");
54 string? agenticAppId = Environment.GetEnvironmentVariable("TEST_AGENTIC_APPID");
55 string? agenticUserId = Environment.GetEnvironmentVariable("TEST_AGENTIC_USERID");
56
57 _agenticIdentity = null;
58 if (!string.IsNullOrEmpty(agenticAppId) && !string.IsNullOrEmpty(agenticUserId))
59 {
60 _recipient.Properties.Add("agenticAppBlueprintId", agenticAppBlueprintId);
61 _recipient.Properties.Add("agenticAppId", agenticAppId);
62 _recipient.Properties.Add("agenticUserId", agenticUserId);
63 _agenticIdentity = AgenticIdentity.FromProperties(_recipient.Properties);
64 }
65 }
66
67 [Fact]
68 public void Api_ReturnsTeamsApiInstance()
69 {
70 TeamsApi api = _teamsBotApplication.Api;
71
72 Assert.NotNull(api);
73 }
74
75 [Fact]
76 public void Api_ReturnsSameInstance()
77 {
78 TeamsApi api1 = _teamsBotApplication.Api;
79 TeamsApi api2 = _teamsBotApplication.Api;
80
81 Assert.Same(api1, api2);
82 }
83
84 [Fact]
85 public void Api_HasAllSubApis()
86 {
87 TeamsApi api = _teamsBotApplication.Api;
88
89 Assert.NotNull(api.Conversations);
90 Assert.NotNull(api.Users);
91 Assert.NotNull(api.Teams);
92 Assert.NotNull(api.Meetings);
93 Assert.NotNull(api.Batch);
94 }
95
96 [Fact]
97 public void Api_Conversations_HasActivitiesAndMembers()
98 {
99 Assert.NotNull(_teamsBotApplication.Api.Conversations.Activities);
100 Assert.NotNull(_teamsBotApplication.Api.Conversations.Members);
101 }
102
103 [Fact]
104 public void Api_Users_HasToken()
105 {
106 Assert.NotNull(_teamsBotApplication.Api.Users.Token);
107 }
108
109 [Fact]
110 public async Task Api_Teams_GetByIdAsync()
111 {
112 string teamId = Environment.GetEnvironmentVariable("TEST_TEAMID") ?? throw new InvalidOperationException("TEST_TEAMID environment variable not set");
113
114 TeamDetails result = await _teamsBotApplication.Api.Teams.GetByIdAsync(
115 teamId,
116 _serviceUrl,
117 _agenticIdentity,
118 cancellationToken: CancellationToken.None);
119
120 Assert.NotNull(result);
121 Assert.NotNull(result.Id);
122
123 Console.WriteLine($"Team details via Api.Teams.GetByIdAsync:");
124 Console.WriteLine($" - Id: {result.Id}");
125 Console.WriteLine($" - Name: {result.Name}");
126 }
127
128 [Fact]
129 public async Task Api_Teams_GetChannelsAsync()
130 {
131 string teamId = Environment.GetEnvironmentVariable("TEST_TEAMID") ?? throw new InvalidOperationException("TEST_TEAMID environment variable not set");
132
133 ChannelList result = await _teamsBotApplication.Api.Teams.GetChannelsAsync(
134 teamId,
135 _serviceUrl,
136 _agenticIdentity,
137 cancellationToken: CancellationToken.None);
138
139 Assert.NotNull(result);
140 Assert.NotNull(result.Channels);
141 Assert.NotEmpty(result.Channels);
142
143 Console.WriteLine($"Found {result.Channels.Count} channels via Api.Teams.GetChannelsAsync:");
144 foreach (var channel in result.Channels)
145 {
146 Console.WriteLine($" - Id: {channel.Id}, Name: {channel.Name}");
147 }
148 }
149
150 [Fact]
151 public async Task Api_Teams_GetByIdAsync_WithActivityContext()
152 {
153 string teamId = Environment.GetEnvironmentVariable("TEST_TEAMID") ?? throw new InvalidOperationException("TEST_TEAMID environment variable not set");
154
155 TeamsActivity activity = new()
156 {
157 ServiceUrl = _serviceUrl,
158 From = TeamsConversationAccount.FromConversationAccount(_recipient),
159 ChannelData = new TeamsChannelData { Team = new Team { Id = teamId } }
160 };
161
162 TeamDetails result = await _teamsBotApplication.Api.Teams.GetByIdAsync(
163 activity,
164 cancellationToken: CancellationToken.None);
165
166 Assert.NotNull(result);
167 Assert.NotNull(result.Id);
168
169 Console.WriteLine($"Team details via Api.Teams.GetByIdAsync with activity context:");
170 Console.WriteLine($" - Id: {result.Id}");
171 }
172
173 [Fact]
174 public async Task Api_Conversations_Activities_SendAsync()
175 {
176 CoreActivity activity = new()
177 {
178 Type = ActivityType.Message,
179 Properties = { { "text", $"Message via Api.Conversations.Activities.SendAsync at `{DateTime.UtcNow:s}`" } },
180 ServiceUrl = _serviceUrl,
181 Conversation = new(_conversationId),
182 From = _recipient
183 };
184
185 SendActivityResponse? res = await _teamsBotApplication.Api.Conversations.Activities.SendAsync(
186 activity,
187 cancellationToken: CancellationToken.None);
188
189 Assert.NotNull(res);
190 Assert.NotNull(res.Id);
191
192 Console.WriteLine($"Sent activity via Api.Conversations.Activities.SendAsync: {res.Id}");
193 }
194
195
196 [Fact]
197 public async Task Api_Conversations_Activities_Send_Update_DeleteTMAsync()
198 {
199 string userId = Environment.GetEnvironmentVariable("TEST_USER_ID") ?? throw new InvalidOperationException("TEST_USER_ID environment variable not set");
200
201 CoreActivity activity = CoreActivity.CreateBuilder()
202 .WithType(ActivityType.Message)
203 .WithServiceUrl(_serviceUrl)
204 .WithConversation(new(_conversationId))
205 .WithFrom(_recipient)
206 .WithRecipient(new ConversationAccount() { Id = userId }, isTargeted: true)
207 .WithProperty("text", $"TM Message via Api.Conversations.Activities.SendAsync at `{DateTime.UtcNow:s}`")
208 .Build();
209
210 SendActivityResponse? res = await _teamsBotApplication.Api.Conversations.Activities.SendAsync(
211 activity,
212 cancellationToken: CancellationToken.None);
213
214 Assert.NotNull(res);
215 Assert.NotNull(res.Id);
216
217 Console.WriteLine($"Sent activity via Api.Conversations.Activities.SendAsync: {res.Id}");
218
219 await Task.Delay(2000);
220
221 await _teamsBotApplication.Api.Conversations.Activities.UpdateTargetedAsync(
222 _conversationId,
223 res.Id,
224 CoreActivity.CreateBuilder()
225 .WithServiceUrl(_serviceUrl)
226 .WithProperty("text", $"TM Updated Message via Api.Conversations.Activities.UpdateAsync at `{DateTime.UtcNow:s}`")
227 .Build(),
228 _agenticIdentity,
229 cancellationToken: CancellationToken.None);
230
231 await Task.Delay(2000);
232 await _teamsBotApplication.Api.Conversations.Activities.DeleteTargetedAsync(
233 _conversationId,
234 res.Id,
235 _serviceUrl,
236 _agenticIdentity,
237 cancellationToken: CancellationToken.None);
238 }
239
240 [Fact]
241 public async Task Api_Conversations_Activities_UpdateAsync()
242 {
243 // First send an activity
244 CoreActivity activity = new()
245 {
246 Type = ActivityType.Message,
247 Properties = { { "text", $"Original message via Api at `{DateTime.UtcNow:s}`" } },
248 ServiceUrl = _serviceUrl,
249 Conversation = new(_conversationId),
250 From = _recipient
251 };
252
253 SendActivityResponse? sendResponse = await _teamsBotApplication.Api.Conversations.Activities.SendAsync(activity);
254 Assert.NotNull(sendResponse?.Id);
255
256 // Now update the activity
257 CoreActivity updatedActivity = new()
258 {
259 Type = ActivityType.Message,
260 Properties = { { "text", $"Updated message via Api.Conversations.Activities.UpdateAsync at `{DateTime.UtcNow:s}`" } },
261 ServiceUrl = _serviceUrl,
262 From = _recipient
263 };
264
265 UpdateActivityResponse updateResponse = await _teamsBotApplication.Api.Conversations.Activities.UpdateAsync(
266 _conversationId,
267 sendResponse.Id,
268 updatedActivity,
269 cancellationToken: CancellationToken.None);
270
271 Assert.NotNull(updateResponse);
272 Assert.NotNull(updateResponse.Id);
273
274 Console.WriteLine($"Updated activity via Api.Conversations.Activities.UpdateAsync: {updateResponse.Id}");
275 }
276
277 [Fact]
278 public async Task Api_Conversations_Activities_DeleteAsync()
279 {
280 // First send an activity
281 CoreActivity activity = new()
282 {
283 Type = ActivityType.Message,
284 Properties = { { "text", $"Message to delete via Api at `{DateTime.UtcNow:s}`" } },
285 ServiceUrl = _serviceUrl,
286 Conversation = new(_conversationId),
287 From = _recipient
288 };
289
290 SendActivityResponse? sendResponse = await _teamsBotApplication.Api.Conversations.Activities.SendAsync(activity);
291 Assert.NotNull(sendResponse?.Id);
292
293 // Wait a bit before deleting
294 await Task.Delay(TimeSpan.FromSeconds(2));
295
296 // Now delete the activity
297 await _teamsBotApplication.Api.Conversations.Activities.DeleteAsync(
298 _conversationId,
299 sendResponse.Id,
300 _serviceUrl,
301 _agenticIdentity,
302 cancellationToken: CancellationToken.None);
303
304 Console.WriteLine($"Deleted activity via Api.Conversations.Activities.DeleteAsync: {sendResponse.Id}");
305 }
306
307 [Fact]
308 public async Task Api_Conversations_Activities_GetMembersAsync()
309 {
310 // First send an activity
311 CoreActivity activity = new()
312 {
313 Type = ActivityType.Message,
314 Properties = { { "text", $"Message for GetMembersAsync test at `{DateTime.UtcNow:s}`" } },
315 ServiceUrl = _serviceUrl,
316 Conversation = new(_conversationId),
317 From = _recipient
318 };
319
320 SendActivityResponse? sendResponse = await _teamsBotApplication.Api.Conversations.Activities.SendAsync(activity);
321 Assert.NotNull(sendResponse?.Id);
322
323 // Now get activity members
324 IList<ConversationAccount> members = await _teamsBotApplication.Api.Conversations.Activities.GetMembersAsync(
325 _conversationId,
326 sendResponse.Id,
327 _serviceUrl,
328 _agenticIdentity,
329 cancellationToken: CancellationToken.None);
330
331 Assert.NotNull(members);
332 Assert.NotEmpty(members);
333
334 Console.WriteLine($"Found {members.Count} activity members via Api.Conversations.Activities.GetMembersAsync:");
335 foreach (var member in members)
336 {
337 Console.WriteLine($" - Id: {member.Id}, Name: {member.Name}");
338 }
339 }
340
341 [Fact]
342 public async Task Api_Conversations_Members_GetAllAsync()
343 {
344 IList<ConversationAccount> members = await _teamsBotApplication.Api.Conversations.Members.GetAllAsync(
345 _conversationId,
346 _serviceUrl,
347 _agenticIdentity,
348 cancellationToken: CancellationToken.None);
349
350 Assert.NotNull(members);
351 Assert.NotEmpty(members);
352
353 Console.WriteLine($"Found {members.Count} conversation members via Api.Conversations.Members.GetAllAsync:");
354 foreach (var member in members)
355 {
356 Console.WriteLine($" - Id: {member.Id}, Name: {member.Name}");
357 }
358 }
359
360 [Fact]
361 public async Task Api_Conversations_Members_GetAllAsync_WithActivityContext()
362 {
363 TeamsActivity activity = new()
364 {
365 ServiceUrl = _serviceUrl,
366 Conversation = new TeamsConversation { Id = _conversationId },
367 From = TeamsConversationAccount.FromConversationAccount(_recipient)
368 };
369
370 IList<ConversationAccount> members = await _teamsBotApplication.Api.Conversations.Members.GetAllAsync(
371 activity,
372 cancellationToken: CancellationToken.None);
373
374 Assert.NotNull(members);
375 Assert.NotEmpty(members);
376
377 Console.WriteLine($"Found {members.Count} members via Api.Conversations.Members.GetAllAsync with activity context");
378 }
379
380 [Fact]
381 public async Task Api_Conversations_Members_GetByIdAsync()
382 {
383 string userId = Environment.GetEnvironmentVariable("TEST_USER_ID") ?? throw new InvalidOperationException("TEST_USER_ID environment variable not set");
384
385 ConversationAccount member = await _teamsBotApplication.Api.Conversations.Members.GetByIdAsync(
386 _conversationId,
387 userId,
388 _serviceUrl,
389 _agenticIdentity,
390 cancellationToken: CancellationToken.None);
391
392 Assert.NotNull(member);
393 Assert.NotNull(member.Id);
394
395 Console.WriteLine($"Found member via Api.Conversations.Members.GetByIdAsync:");
396 Console.WriteLine($" - Id: {member.Id}, Name: {member.Name}");
397 }
398
399 [Fact]
400 public async Task Api_Conversations_Members_GetPagedAsync()
401 {
402 PagedMembersResult result = await _teamsBotApplication.Api.Conversations.Members.GetPagedAsync(
403 _conversationId,
404 _serviceUrl,
405 5,
406 null,
407 _agenticIdentity,
408 cancellationToken: CancellationToken.None);
409
410 Assert.NotNull(result);
411 Assert.NotNull(result.Members);
412 Assert.NotEmpty(result.Members);
413
414 Console.WriteLine($"Found {result.Members.Count} members via Api.Conversations.Members.GetPagedAsync");
415 }
416
417 [Fact(Skip = "GetByIdAsync is not working with agentic identity")]
418 public async Task Api_Meetings_GetByIdAsync()
419 {
420 string meetingId = Environment.GetEnvironmentVariable("TEST_MEETINGID") ?? throw new InvalidOperationException("TEST_MEETINGID environment variable not set");
421
422 MeetingInfo result = await _teamsBotApplication.Api.Meetings.GetByIdAsync(
423 meetingId,
424 _serviceUrl,
425 _agenticIdentity,
426 cancellationToken: CancellationToken.None);
427
428 Assert.NotNull(result);
429
430 Console.WriteLine($"Meeting info via Api.Meetings.GetByIdAsync:");
431 if (result.Details != null)
432 {
433 Console.WriteLine($" - Title: {result.Details.Title}");
434 Console.WriteLine($" - Type: {result.Details.Type}");
435 }
436 }
437
438 [Fact]
439 public async Task Api_Meetings_GetParticipantAsync()
440 {
441 string meetingId = Environment.GetEnvironmentVariable("TEST_MEETINGID") ?? throw new InvalidOperationException("TEST_MEETINGID environment variable not set");
442 string participantId = Environment.GetEnvironmentVariable("TEST_USER_ID") ?? throw new InvalidOperationException("TEST_USER_ID environment variable not set");
443 string tenantId = Environment.GetEnvironmentVariable("TEST_TENANTID") ?? throw new InvalidOperationException("TEST_TENANTID environment variable not set");
444
445 MeetingParticipant result = await _teamsBotApplication.Api.Meetings.GetParticipantAsync(
446 meetingId,
447 participantId,
448 tenantId,
449 _serviceUrl,
450 _agenticIdentity,
451 cancellationToken: CancellationToken.None);
452
453 Assert.NotNull(result);
454
455 Console.WriteLine($"Participant info via Api.Meetings.GetParticipantAsync:");
456 if (result.User != null)
457 {
458 Console.WriteLine($" - User Id: {result.User.Id}");
459 Console.WriteLine($" - User Name: {result.User.Name}");
460 }
461 }
462
463 [Fact]
464 public async Task Api_Batch_GetStateAsync_FailsWithInvalidOperationId()
465 {
466 await Assert.ThrowsAsync<HttpRequestException>(()
467 => _teamsBotApplication.Api.Batch.GetStateAsync("invalid-operation-id", _serviceUrl, _agenticIdentity));
468 }
469
470 [Fact]
471 public async Task Api_Teams_GetByIdAsync_ThrowsOnNullActivity()
472 {
473 await Assert.ThrowsAsync<ArgumentNullException>(()
474 => _teamsBotApplication.Api.Teams.GetByIdAsync((TeamsActivity)null!));
475 }
476
477 [Fact]
478 public async Task Api_Teams_GetChannelsAsync_ThrowsOnNullActivity()
479 {
480 await Assert.ThrowsAsync<ArgumentNullException>(()
481 => _teamsBotApplication.Api.Teams.GetChannelsAsync((TeamsActivity)null!));
482 }
483
484 [Fact]
485 public async Task Api_Conversations_Members_GetAllAsync_ThrowsOnNullActivity()
486 {
487 await Assert.ThrowsAsync<ArgumentNullException>(()
488 => _teamsBotApplication.Api.Conversations.Members.GetAllAsync((TeamsActivity)null!));
489 }
490
491 [Fact]
492 public async Task Api_Conversations_Members_GetByIdAsync_ThrowsOnNullActivity()
493 {
494 await Assert.ThrowsAsync<ArgumentNullException>(()
495 => _teamsBotApplication.Api.Conversations.Members.GetByIdAsync((TeamsActivity)null!, "user-id"));
496 }
497
498 [Fact]
499 public async Task Api_Conversations_Members_GetPagedAsync_ThrowsOnNullActivity()
500 {
501 await Assert.ThrowsAsync<ArgumentNullException>(()
502 => _teamsBotApplication.Api.Conversations.Members.GetPagedAsync((TeamsActivity)null!));
503 }
504
505 [Fact]
506 public async Task Api_Conversations_Members_DeleteAsync_ThrowsOnNullActivity()
507 {
508 await Assert.ThrowsAsync<ArgumentNullException>(()
509 => _teamsBotApplication.Api.Conversations.Members.DeleteAsync((TeamsActivity)null!, "member-id"));
510 }
511
512 [Fact]
513 public async Task Api_Meetings_GetByIdAsync_ThrowsOnNullActivity()
514 {
515 await Assert.ThrowsAsync<ArgumentNullException>(()
516 => _teamsBotApplication.Api.Meetings.GetByIdAsync("meeting-id", (TeamsActivity)null!));
517 }
518
519 [Fact]
520 public async Task Api_Meetings_GetParticipantAsync_ThrowsOnNullActivity()
521 {
522 await Assert.ThrowsAsync<ArgumentNullException>(()
523 => _teamsBotApplication.Api.Meetings.GetParticipantAsync("meeting-id", "participant-id", (TeamsActivity)null!));
524 }
525
526 [Fact]
527 public async Task Api_Meetings_SendNotificationAsync_ThrowsOnNullActivity()
528 {
529 var notification = new TargetedMeetingNotification();
530 await Assert.ThrowsAsync<ArgumentNullException>(()
531 => _teamsBotApplication.Api.Meetings.SendNotificationAsync("meeting-id", notification, (TeamsActivity)null!));
532 }
533
534 [Fact]
535 public async Task Api_Batch_GetStateAsync_ThrowsOnNullActivity()
536 {
537 await Assert.ThrowsAsync<ArgumentNullException>(()
538 => _teamsBotApplication.Api.Batch.GetStateAsync("operation-id", (TeamsActivity)null!));
539 }
540
541 [Fact]
542 public async Task Api_Batch_GetFailedEntriesAsync_ThrowsOnNullActivity()
543 {
544 await Assert.ThrowsAsync<ArgumentNullException>(()
545 => _teamsBotApplication.Api.Batch.GetFailedEntriesAsync("operation-id", (TeamsActivity)null!));
546 }
547
548 [Fact]
549 public async Task Api_Batch_CancelAsync_ThrowsOnNullActivity()
550 {
551 await Assert.ThrowsAsync<ArgumentNullException>(()
552 => _teamsBotApplication.Api.Batch.CancelAsync("operation-id", (TeamsActivity)null!));
553 }
554
555 [Fact]
556 public async Task Api_Batch_SendToUsersAsync_ThrowsOnNullActivity()
557 {
558 var activity = new CoreActivity { Type = ActivityType.Message };
559 await Assert.ThrowsAsync<ArgumentNullException>(()
560 => _teamsBotApplication.Api.Batch.SendToUsersAsync(activity, [new TeamMember("id")], (TeamsActivity)null!));
561 }
562
563 [Fact]
564 public async Task Api_Batch_SendToTenantAsync_ThrowsOnNullActivity()
565 {
566 var activity = new CoreActivity { Type = ActivityType.Message };
567 await Assert.ThrowsAsync<ArgumentNullException>(()
568 => _teamsBotApplication.Api.Batch.SendToTenantAsync(activity, (TeamsActivity)null!));
569 }
570
571 [Fact]
572 public async Task Api_Batch_SendToTeamAsync_ThrowsOnNullActivity()
573 {
574 var activity = new CoreActivity { Type = ActivityType.Message };
575 await Assert.ThrowsAsync<ArgumentNullException>(()
576 => _teamsBotApplication.Api.Batch.SendToTeamAsync(activity, "team-id", (TeamsActivity)null!));
577 }
578
579 [Fact]
580 public async Task Api_Batch_SendToChannelsAsync_ThrowsOnNullActivity()
581 {
582 var activity = new CoreActivity { Type = ActivityType.Message };
583 await Assert.ThrowsAsync<ArgumentNullException>(()
584 => _teamsBotApplication.Api.Batch.SendToChannelsAsync(activity, [new TeamMember("id")], (TeamsActivity)null!));
585 }
586
587 [Fact]
588 public async Task Api_Users_Token_GetAsync_ThrowsOnNullActivity()
589 {
590 await Assert.ThrowsAsync<ArgumentNullException>(()
591 => _teamsBotApplication.Api.Users.Token.GetAsync((TeamsActivity)null!, "connection-name"));
592 }
593
594 [Fact]
595 public async Task Api_Users_Token_ExchangeAsync_ThrowsOnNullActivity()
596 {
597 await Assert.ThrowsAsync<ArgumentNullException>(()
598 => _teamsBotApplication.Api.Users.Token.ExchangeAsync((TeamsActivity)null!, "connection-name", "token"));
599 }
600
601 [Fact]
602 public async Task Api_Users_Token_SignOutAsync_ThrowsOnNullActivity()
603 {
604 await Assert.ThrowsAsync<ArgumentNullException>(()
605 => _teamsBotApplication.Api.Users.Token.SignOutAsync((TeamsActivity)null!));
606 }
607
608 [Fact]
609 public async Task Api_Users_Token_GetAadTokensAsync_ThrowsOnNullActivity()
610 {
611 await Assert.ThrowsAsync<ArgumentNullException>(()
612 => _teamsBotApplication.Api.Users.Token.GetAadTokensAsync((TeamsActivity)null!, "connection-name"));
613 }
614
615 [Fact]
616 public async Task Api_Users_Token_GetStatusAsync_ThrowsOnNullActivity()
617 {
618 await Assert.ThrowsAsync<ArgumentNullException>(()
619 => _teamsBotApplication.Api.Users.Token.GetStatusAsync((TeamsActivity)null!));
620 }
621
622 [Fact]
623 public async Task Api_Users_Token_GetSignInResourceAsync_ThrowsOnNullActivity()
624 {
625 await Assert.ThrowsAsync<ArgumentNullException>(()
626 => _teamsBotApplication.Api.Users.Token.GetSignInResourceAsync((TeamsActivity)null!, "connection-name"));
627 }
628
629 [Fact]
630 public async Task Api_Conversations_Activities_SendHistoryAsync_ThrowsOnNullActivity()
631 {
632 var transcript = new Transcript { Activities = [] };
633 await Assert.ThrowsAsync<ArgumentNullException>(()
634 => _teamsBotApplication.Api.Conversations.Activities.SendHistoryAsync((TeamsActivity)null!, transcript));
635 }
636
637 [Fact]
638 public async Task Api_Conversations_Activities_GetMembersAsync_ThrowsOnNullActivity()
639 {
640 await Assert.ThrowsAsync<ArgumentNullException>(()
641 => _teamsBotApplication.Api.Conversations.Activities.GetMembersAsync((TeamsActivity)null!));
642 }
643}
644