microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/move-activity-implementations

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/test/Microsoft.Bot.Core.Tests/ConversationClientTest.cs

87lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Bot.Core.Hosting;
5using Microsoft.Bot.Core.Schema;
6using Microsoft.Extensions.Configuration;
7using Microsoft.Extensions.DependencyInjection;
8
9namespace Microsoft.Bot.Core.Tests;
10
11public class ConversationClientTest
12{
13 private readonly ServiceProvider _serviceProvider;
14 private readonly ConversationClient _conversationClient;
15
16 public ConversationClientTest()
17 {
18 IConfigurationBuilder builder = new ConfigurationBuilder()
19 .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
20 .AddEnvironmentVariables();
21
22 IConfiguration configuration = builder.Build();
23
24 ServiceCollection services = new();
25 services.AddSingleton(configuration);
26 services.AddBotApplicationClients();
27 _serviceProvider = services.BuildServiceProvider();
28 _conversationClient = _serviceProvider.GetRequiredService<ConversationClient>();
29
30 }
31
32 [Fact]
33 public async Task SendActivityDefault()
34 {
35 CoreActivity activity = new()
36 {
37 Type = ActivityTypes.Message,
38 Text = $"Message from Automated tests, running in SDK `{BotApplication.Version}` at `{DateTime.UtcNow:s}`",
39 ServiceUrl = new Uri("https://smba.trafficmanager.net/teams/"),
40 Conversation = new()
41 {
42 Id = Environment.GetEnvironmentVariable("TEST_CONVERSATIONID") ?? throw new InvalidOperationException("TEST_ConversationId environment variable not set")
43 }
44 };
45 string res = await _conversationClient.SendActivityAsync(activity, CancellationToken.None);
46 Assert.NotNull(res);
47 Assert.Contains("\"id\"", res);
48 }
49
50
51
52 [Fact]
53 public async Task SendActivityToChannel()
54 {
55 CoreActivity activity = new()
56 {
57 Type = ActivityTypes.Message,
58 Text = $"Message from Automated tests, running in SDK `{BotApplication.Version}` at `{DateTime.UtcNow:s}`",
59 ServiceUrl = new Uri("https://smba.trafficmanager.net/teams/"),
60 Conversation = new()
61 {
62 Id = "19:9f2af1bee7cc4a71af25ac72478fd5c6@thread.tacv2"
63 }
64 };
65 string res = await _conversationClient.SendActivityAsync(activity, CancellationToken.None);
66 Assert.NotNull(res);
67 Assert.Contains("\"id\"", res);
68 }
69
70 [Fact]
71 public async Task SendActivityToPersonalChat_FailsWithBad_ConversationId()
72 {
73 CoreActivity activity = new()
74 {
75 Type = ActivityTypes.Message,
76 Text = $"Message from Automated tests, running in SDK `{BotApplication.Version}` at `{DateTime.UtcNow:s}`",
77 ServiceUrl = new Uri("https://smba.trafficmanager.net/teams/"),
78 Conversation = new()
79 {
80 Id = "a:1"
81 }
82 };
83
84 await Assert.ThrowsAsync<HttpRequestException>(()
85 => _conversationClient.SendActivityAsync(activity));
86 }
87}
88