microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev

Branches

Tags

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

Clone

HTTPS

Download ZIP

Tests/Microsoft.Teams.Apps.Tests/Concurrency/AsyncTests.cs

75lines · modecode

1using Microsoft.Extensions.DependencyInjection;
2using Microsoft.Teams.Api.Activities.Invokes;
3using Microsoft.Teams.Api.Auth;
4using Microsoft.Teams.Apps.Activities.Invokes;
5using Microsoft.Teams.Apps.Annotations;
6using Microsoft.Teams.Apps.Testing.Plugins;
7
8namespace Microsoft.Teams.Apps.Tests.Concurrency;
9
10public class AsynTests
11{
12 private readonly App _app = new();
13 private readonly IToken _token = Globals.Token;
14 private readonly TestPlugin _plugin = new();
15 private readonly IServiceProvider _provider;
16
17 public AsynTests()
18 {
19 var services = new ServiceCollection();
20 services.AddSingleton<IContext.Accessor>();
21 services.AddSingleton<Controller>();
22
23 _provider = services.BuildServiceProvider();
24 _app.AddController(_provider.GetRequiredService<Controller>());
25 _app.AddPlugin(_plugin);
26 }
27
28 [Fact]
29 public async Task Should_Have_Unique_Data()
30 {
31 var tasks = new List<Task<Response>>();
32
33 for (var i = 0; i < 200; i++)
34 {
35 tasks.Add(_plugin.Do(
36 new()
37 {
38 Token = _token,
39 Activity = new Messages.SubmitActionActivity()
40 {
41 Value = new()
42 {
43 ActionName = "name",
44 ActionValue = "value"
45 }
46 },
47 Extra = new Dictionary<string, object?>()
48 {
49 { "index", i }
50 },
51 Services = _provider.CreateScope().ServiceProvider
52 }
53 ));
54 }
55
56 var responses = await Task.WhenAll(tasks.ToArray());
57
58 for (var i = 0; i < 200; i++)
59 {
60 Assert.Equal(i, responses[i].Body);
61 }
62 }
63
64 [TeamsController]
65 public class Controller(IContext.Accessor accessor)
66 {
67 [Message.SubmitAction]
68 public Task<object?> OnSubmitAction(IContext<Messages.SubmitActionActivity> context)
69 {
70 Assert.NotNull(accessor.Value);
71 Assert.Equal(accessor.Value.Extra["index"], context.Extra["index"]);
72 return Task.FromResult(context.Extra["index"]);
73 }
74 }
75}