microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/test/IntegrationTests/ConversationClientTests.cs
174lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Core; |
| 5 | using Microsoft.Teams.Core.Schema; |
| 6 | using Xunit.Abstractions; |
| 7 | |
| 8 | namespace IntegrationTests; |
| 9 | |
| 10 | /// <summary> |
| 11 | /// Integration tests for core <see cref="ConversationClient"/> making real API calls. |
| 12 | /// </summary> |
| 13 | public 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 | [Trait("Category", "Activities")] |
| 27 | public async Task SendActivity() |
| 28 | { |
| 29 | CoreActivity activity = CoreActivity.CreateBuilder() |
| 30 | .WithType(ActivityType.Message) |
| 31 | .WithFrom(IntegrationTestFixture.GetChannelAccountWithAgenticProperties()) |
| 32 | .WithServiceUrl(_f.ServiceUrl) |
| 33 | .WithConversation(new(_f.ConversationId)) |
| 34 | .WithProperty("text", $"[ConversationClient] SendActivity at `{DateTime.UtcNow:s}`") |
| 35 | .Build(); |
| 36 | |
| 37 | SendActivityResponse? res = await _f.ConversationClient.SendActivityAsync(activity); |
| 38 | |
| 39 | Assert.NotNull(res); |
| 40 | Assert.NotNull(res.Id); |
| 41 | _output.WriteLine($"Sent activity: {res.Id}"); |
| 42 | } |
| 43 | |
| 44 | [Fact(Timeout = 5000)] |
| 45 | [Trait("Category", "Activities")] |
| 46 | public async Task UpdateActivity() |
| 47 | { |
| 48 | CoreActivity activity = CoreActivity.CreateBuilder() |
| 49 | .WithType(ActivityType.Message) |
| 50 | .WithFrom(IntegrationTestFixture.GetChannelAccountWithAgenticProperties()) |
| 51 | .WithServiceUrl(_f.ServiceUrl) |
| 52 | .WithConversation(new(_f.ConversationId)) |
| 53 | .WithProperty("text", $"[ConversationClient] Original at `{DateTime.UtcNow:s}`") |
| 54 | .Build(); |
| 55 | |
| 56 | SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity); |
| 57 | Assert.NotNull(sent?.Id); |
| 58 | |
| 59 | CoreActivity updated = CoreActivity.CreateBuilder() |
| 60 | .WithType(ActivityType.Message) |
| 61 | .WithFrom(IntegrationTestFixture.GetChannelAccountWithAgenticProperties()) |
| 62 | .WithServiceUrl(_f.ServiceUrl) |
| 63 | .WithConversation(new(_f.ConversationId)) |
| 64 | .WithProperty("text", $"[ConversationClient] Updated at `{DateTime.UtcNow:s}`") |
| 65 | .Build(); |
| 66 | |
| 67 | UpdateActivityResponse res = await _f.ConversationClient.UpdateActivityAsync( |
| 68 | _f.ConversationId, sent.Id, updated, false, _f.AgenticIdentity); |
| 69 | |
| 70 | Assert.NotNull(res?.Id); |
| 71 | _output.WriteLine($"Updated activity: {res.Id}"); |
| 72 | } |
| 73 | |
| 74 | [Fact(Timeout = 5000)] |
| 75 | [Trait("Category", "Activities")] |
| 76 | public async Task DeleteActivity() |
| 77 | { |
| 78 | CoreActivity activity = CoreActivity.CreateBuilder() |
| 79 | .WithType(ActivityType.Message) |
| 80 | .WithFrom(IntegrationTestFixture.GetChannelAccountWithAgenticProperties()) |
| 81 | .WithServiceUrl(_f.ServiceUrl) |
| 82 | .WithConversation(new(_f.ConversationId)) |
| 83 | .WithProperty("text", $"[ConversationClient] To delete at `{DateTime.UtcNow:s}`") |
| 84 | .Build(); |
| 85 | |
| 86 | SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity); |
| 87 | Assert.NotNull(sent?.Id); |
| 88 | |
| 89 | await Task.Delay(2000); |
| 90 | |
| 91 | await _f.ConversationClient.DeleteActivityAsync( |
| 92 | _f.ConversationId, sent.Id, _f.ServiceUrl, _f.AgenticIdentity); |
| 93 | |
| 94 | _output.WriteLine($"Deleted activity: {sent.Id}"); |
| 95 | } |
| 96 | |
| 97 | [Fact(Timeout = 5000)] |
| 98 | [Trait("Category", "Activities")] |
| 99 | public async Task GetConversationMembers() |
| 100 | { |
| 101 | IList<ChannelAccount> members = await _f.ConversationClient.GetConversationMembersAsync( |
| 102 | _f.ConversationId, _f.ServiceUrl, _f.AgenticIdentity); |
| 103 | |
| 104 | Assert.NotNull(members); |
| 105 | Assert.NotEmpty(members); |
| 106 | |
| 107 | foreach (ChannelAccount m in members) |
| 108 | { |
| 109 | _output.WriteLine($"Member: {m.Id} — {m.Name}"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | [Fact(Timeout = 5000)] |
| 114 | [Trait("Category", "Activities")] |
| 115 | public async Task GetConversationMember() |
| 116 | { |
| 117 | string memberId = _f.MemberMri1!; |
| 118 | |
| 119 | ChannelAccount member = await _f.ConversationClient.GetConversationMemberAsync<ChannelAccount>( |
| 120 | _f.ConversationId, memberId, _f.ServiceUrl, _f.AgenticIdentity); |
| 121 | |
| 122 | Assert.NotNull(member); |
| 123 | Assert.Equal(memberId, member.Id); |
| 124 | _output.WriteLine($"Member: {member.Id} — {member.Name}"); |
| 125 | } |
| 126 | |
| 127 | [SkippableFact(Timeout = 5000)] |
| 128 | [Trait("Category", "Activities")] |
| 129 | public async Task GetPagedMembers() |
| 130 | { |
| 131 | Skip.If(_f.AgenticIdentity is not null, "Paged members returns 500 with agentic identity — service limitation"); |
| 132 | Skip.If(_f.IsCanary, "Paged members returns empty on canary — service limitation"); |
| 133 | |
| 134 | PagedMembersResult result = await _f.ConversationClient.GetConversationPagedMembersAsync( |
| 135 | _f.ConversationId, _f.ServiceUrl, pageSize: 5, agenticIdentity: _f.AgenticIdentity); |
| 136 | |
| 137 | Assert.NotNull(result?.Members); |
| 138 | Assert.NotEmpty(result.Members); |
| 139 | |
| 140 | foreach (ChannelAccount m in result.Members.Take(5)) |
| 141 | { |
| 142 | _output.WriteLine($"Member: {m.Id} — {m.Name}"); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | [SkippableFact] |
| 147 | [Trait("Category", "Activities")] |
| 148 | public async Task AddAndDeleteReaction() |
| 149 | { |
| 150 | Skip.If(_f.AgenticIdentity is not null, "Reactions API returns 404 with agentic identity — service limitation"); |
| 151 | Skip.If(_f.IsCanary, "Reactions API returns 404 on canary — service limitation"); |
| 152 | |
| 153 | CoreActivity activity = CoreActivity.CreateBuilder() |
| 154 | .WithType(ActivityType.Message) |
| 155 | .WithServiceUrl(_f.ServiceUrl) |
| 156 | .WithFrom(IntegrationTestFixture.GetChannelAccountWithAgenticProperties()) |
| 157 | .WithConversation(new(_f.ConversationId)) |
| 158 | .WithProperty("text", $"[ConversationClient] Reaction test at `{DateTime.UtcNow:s}`") |
| 159 | .Build(); |
| 160 | |
| 161 | SendActivityResponse? sent = await _f.ConversationClient.SendActivityAsync(activity); |
| 162 | Assert.NotNull(sent?.Id); |
| 163 | |
| 164 | await _f.ConversationClient.AddReactionAsync( |
| 165 | _f.ConversationId, sent.Id, "like", _f.ServiceUrl, _f.AgenticIdentity); |
| 166 | _output.WriteLine("Added 'like' reaction"); |
| 167 | |
| 168 | await Task.Delay(1000); |
| 169 | |
| 170 | await _f.ConversationClient.DeleteReactionAsync( |
| 171 | _f.ConversationId, sent.Id, "like", _f.ServiceUrl, _f.AgenticIdentity); |
| 172 | _output.WriteLine("Removed 'like' reaction"); |
| 173 | } |
| 174 | } |
| 175 | |