microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/core-compat-sso-middleware

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/test/IntegrationTests/ConversationClientTests.cs

165lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Bot.Core;
5using Microsoft.Teams.Bot.Core.Schema;
6using Xunit.Abstractions;
7
8namespace IntegrationTests;
9
10/// <summary>
11/// Integration tests for core <see cref="ConversationClient"/> making real API calls.
12/// </summary>
13public class ConversationClientTests : IClassFixture<IntegrationTestFixture>
14{
15 private readonly IntegrationTestFixture _f;
16 private readonly ITestOutputHelper _output;
17
18 public ConversationClientTests(IntegrationTestFixture fixture, ITestOutputHelper output)
19 {
20 _f = fixture;
21 _f.OutputHelper = output;
22 _output = output;
23 }
24
25 [Fact]
26 public async Task SendActivity()
27 {
28 CoreActivity activity = new()
29 {
30 Type = ActivityType.Message,
31 Properties = { { "text", $"[ConversationClient] SendActivity at `{DateTime.UtcNow:s}`" } },
32 ServiceUrl = _f.ServiceUrl,
33 Conversation = new(_f.ConversationId)
34 };
35
36 SendActivityResponse? res = await _f.ConversationClient.SendActivityAsync(activity);
37
38 Assert.NotNull(res);
39 Assert.NotNull(res.Id);
40 _output.WriteLine($"Sent activity: {res.Id}");
41 }
42
43 [Fact]
44 public async Task UpdateActivity()
45 {
46 CoreActivity activity = new()
47 {
48 Type = ActivityType.Message,
49 Properties = { { "text", $"[ConversationClient] Original at `{DateTime.UtcNow:s}`" } },
50 ServiceUrl = _f.ServiceUrl,
51 Conversation = new(_f.ConversationId)
52 };
53
54 SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity);
55 Assert.NotNull(sent?.Id);
56
57 CoreActivity updated = new()
58 {
59 Type = ActivityType.Message,
60 Properties = { { "text", $"[ConversationClient] Updated at `{DateTime.UtcNow:s}`" } },
61 ServiceUrl = _f.ServiceUrl,
62 Conversation = new(_f.ConversationId)
63 };
64
65 UpdateActivityResponse res = await _f.ConversationClient.UpdateActivityAsync(
66 _f.ConversationId, sent.Id, updated);
67
68 Assert.NotNull(res?.Id);
69 _output.WriteLine($"Updated activity: {res.Id}");
70 }
71
72 [Fact]
73 public async Task DeleteActivity()
74 {
75 CoreActivity activity = new()
76 {
77 Type = ActivityType.Message,
78 Properties = { { "text", $"[ConversationClient] To delete at `{DateTime.UtcNow:s}`" } },
79 ServiceUrl = _f.ServiceUrl,
80 Conversation = new(_f.ConversationId)
81 };
82
83 SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity);
84 Assert.NotNull(sent?.Id);
85
86 await Task.Delay(2000);
87
88 await _f.ConversationClient.DeleteActivityAsync(
89 _f.ConversationId, sent.Id, _f.ServiceUrl);
90
91 _output.WriteLine($"Deleted activity: {sent.Id}");
92 }
93
94 [Fact]
95 public async Task GetConversationMembers()
96 {
97 IList<ConversationAccount> members = await _f.ConversationClient.GetConversationMembersAsync(
98 _f.ConversationId, _f.ServiceUrl, _f.AgenticIdentity);
99
100 Assert.NotNull(members);
101 Assert.NotEmpty(members);
102
103 foreach (ConversationAccount m in members)
104 {
105 _output.WriteLine($"Member: {m.Id} — {m.Name}");
106 }
107 }
108
109 [Fact]
110 public async Task GetConversationMember()
111 {
112 // Get MRI-format member ID from the members list first
113 IList<ConversationAccount> members = await _f.ConversationClient.GetConversationMembersAsync(
114 _f.ConversationId, _f.ServiceUrl, _f.AgenticIdentity);
115 Assert.NotEmpty(members);
116 string memberId = members[0].Id!;
117
118 ConversationAccount member = await _f.ConversationClient.GetConversationMemberAsync<ConversationAccount>(
119 _f.ConversationId, memberId, _f.ServiceUrl, _f.AgenticIdentity);
120
121 Assert.NotNull(member);
122 Assert.Equal(memberId, member.Id);
123 _output.WriteLine($"Member: {member.Id} — {member.Name}");
124 }
125
126 [Fact]
127 public async Task GetPagedMembers()
128 {
129 PagedMembersResult result = await _f.ConversationClient.GetConversationPagedMembersAsync(
130 _f.ConversationId, _f.ServiceUrl, pageSize: 5, agenticIdentity: _f.AgenticIdentity);
131
132 Assert.NotNull(result?.Members);
133 Assert.NotEmpty(result.Members);
134
135 foreach (ConversationAccount m in result.Members)
136 {
137 _output.WriteLine($"Member: {m.Id} — {m.Name}");
138 }
139 }
140
141 [Fact(Skip = "Reactions endpoint does not exist in Teams Bot Framework API (experimental/assumed route)")]
142 public async Task AddAndDeleteReaction()
143 {
144 CoreActivity activity = new()
145 {
146 Type = ActivityType.Message,
147 Properties = { { "text", $"[ConversationClient] Reaction test at `{DateTime.UtcNow:s}`" } },
148 ServiceUrl = _f.ServiceUrl,
149 Conversation = new(_f.ConversationId)
150 };
151
152 SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity);
153 Assert.NotNull(sent?.Id);
154
155 await _f.ConversationClient.AddReactionAsync(
156 _f.ConversationId, sent.Id, "like", _f.ServiceUrl, _f.AgenticIdentity);
157 _output.WriteLine("Added 'like' reaction");
158
159 await Task.Delay(1000);
160
161 await _f.ConversationClient.DeleteReactionAsync(
162 _f.ConversationId, sent.Id, "like", _f.ServiceUrl, _f.AgenticIdentity);
163 _output.WriteLine("Removed 'like' reaction");
164 }
165}
166