microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
releases/v2

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.Core;
5using Microsoft.Teams.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(Timeout = 5000)]
26 public async Task SendActivity()
27 {
28 CoreActivity activity = CoreActivity.CreateBuilder()
29 .WithType(ActivityType.Message)
30 .WithFrom(IntegrationTestFixture.GetConversationAccountWithAgenticProperties())
31 .WithServiceUrl(_f.ServiceUrl)
32 .WithConversation(new(_f.ConversationId))
33 .WithProperty("text", $"[ConversationClient] SendActivity at `{DateTime.UtcNow:s}`")
34 .Build();
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(Timeout = 5000)]
44 public async Task UpdateActivity()
45 {
46 CoreActivity activity = CoreActivity.CreateBuilder()
47 .WithType(ActivityType.Message)
48 .WithFrom(IntegrationTestFixture.GetConversationAccountWithAgenticProperties())
49 .WithServiceUrl(_f.ServiceUrl)
50 .WithConversation(new(_f.ConversationId))
51 .WithProperty("text", $"[ConversationClient] Original at `{DateTime.UtcNow:s}`")
52 .Build();
53
54 SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity);
55 Assert.NotNull(sent?.Id);
56
57 CoreActivity updated = CoreActivity.CreateBuilder()
58 .WithType(ActivityType.Message)
59 .WithFrom(IntegrationTestFixture.GetConversationAccountWithAgenticProperties())
60 .WithServiceUrl(_f.ServiceUrl)
61 .WithConversation(new(_f.ConversationId))
62 .WithProperty("text", $"[ConversationClient] Updated at `{DateTime.UtcNow:s}`")
63 .Build();
64
65 UpdateActivityResponse res = await _f.ConversationClient.UpdateActivityAsync(
66 _f.ConversationId, sent.Id, updated, false, _f.AgenticIdentity);
67
68 Assert.NotNull(res?.Id);
69 _output.WriteLine($"Updated activity: {res.Id}");
70 }
71
72 [Fact(Timeout = 5000)]
73 public async Task DeleteActivity()
74 {
75 CoreActivity activity = CoreActivity.CreateBuilder()
76 .WithType(ActivityType.Message)
77 .WithFrom(IntegrationTestFixture.GetConversationAccountWithAgenticProperties())
78 .WithServiceUrl(_f.ServiceUrl)
79 .WithConversation(new(_f.ConversationId))
80 .WithProperty("text", $"[ConversationClient] To delete at `{DateTime.UtcNow:s}`")
81 .Build();
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, _f.AgenticIdentity);
90
91 _output.WriteLine($"Deleted activity: {sent.Id}");
92 }
93
94 [Fact(Timeout = 5000, Skip = "GET /members throttled on canary — cached fixture needed")]
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(Timeout = 5000, Skip = "GET /members throttled on canary — cached fixture needed")]
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(Timeout = 5000, Skip = "GET /members throttled on canary — cached fixture needed")]
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]
142 public async Task AddAndDeleteReaction()
143 {
144 CoreActivity activity = CoreActivity.CreateBuilder()
145 .WithType(ActivityType.Message)
146 .WithServiceUrl(_f.ServiceUrl)
147 .WithFrom(IntegrationTestFixture.GetConversationAccountWithAgenticProperties())
148 .WithConversation(new(_f.ConversationId))
149 .WithProperty("text", $"[ConversationClient] Reaction test at `{DateTime.UtcNow:s}`")
150 .Build();
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