microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/update-release-process

Branches

Tags

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

Clone

HTTPS

Download ZIP

Tests/Microsoft.Teams.Apps.Tests/Activities/Events/MeetingJoinEventTests.cs

168lines · modecode

1
2using Microsoft.Teams.Api;
3using Microsoft.Teams.Api.Activities;
4using Microsoft.Teams.Api.Activities.Events;
5using Microsoft.Teams.Api.Auth;
6using Microsoft.Teams.Apps.Activities.Events;
7using Microsoft.Teams.Apps.Testing.Plugins;
8
9using static Microsoft.Teams.Apps.Activities.Events.Event;
10
11namespace Microsoft.Teams.Apps.Tests.Activities.Events;
12
13public class MeetingJoinEventTests
14{
15 private readonly App _app = new();
16 private readonly TestPlugin _plugin = new();
17 private readonly MeetingActivityController _controller = new();
18 private readonly IToken _token = Globals.Token;
19
20 public MeetingJoinEventTests()
21 {
22 _app.AddPlugin(_plugin);
23 _app.AddController(_controller);
24 _token = Globals.Token;
25 }
26
27 [Fact]
28 public async Task Should_CallHandler_OnMeetingJoinEvent()
29 {
30 // Arrange
31 var handlerCalled = false;
32 var eventContext = default(IContext<MeetingParticipantJoinActivity>);
33
34 _app.OnMeetingJoin(context =>
35 {
36 handlerCalled = true;
37 eventContext = context;
38 return Task.FromResult<object?>(null);
39 });
40
41 // Create a MeetingJoinActivity
42 var meetingJoinActivity = new MeetingParticipantJoinActivity
43 {
44 Value = new MeetingParticipantJoinActivityValue
45 {
46 Members = new List<MeetingParticipantJoinActivityValue.Member>
47 {
48 new MeetingParticipantJoinActivityValue.Member
49 {
50 User = new Account { Id = "user1", Name = "Test User" },
51 Meeting = new MeetingParticipantJoinActivityValue.Meeting
52 {
53 InMeeting = true,
54 Role = Role.User
55 }
56 },
57
58 }
59 }
60 };
61
62 // Act
63 var res = await _plugin.Do(_token, meetingJoinActivity);
64
65 // Assert
66 Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
67 Assert.True(handlerCalled, "The MeetingJoin event handler should be called");
68 Assert.NotNull(eventContext);
69 Assert.IsType<MeetingParticipantJoinActivity>(eventContext.Activity);
70 Assert.Single(eventContext.Activity.Value.Members);
71 }
72
73 [Fact]
74 public async Task Should_NotCallHandler_ForOtherEventTypes()
75 {
76 // Arrange
77 var handlerCalled = false;
78
79 _app.OnMeetingJoin(context =>
80 {
81 handlerCalled = true;
82 return Task.FromResult<object?>(null);
83 });
84
85 // Act - SJoin a different activity type
86 var res = await _plugin.Do(_token, new MessageActivity("hello world"));
87
88 // Assert
89 Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
90 Assert.False(handlerCalled, "The MeetingJoin event handler should not be called for other activity types");
91 }
92
93 [Fact]
94 public void MeetingJoinAttribute_Select_ReturnsTrueForMeetingJoinActivity()
95 {
96 // Arrange
97 var attribute = new MeetingJoinAttribute();
98 var activity = new MeetingParticipantJoinActivity
99 {
100 Value = new MeetingParticipantJoinActivityValue
101 {
102 Members = new List<MeetingParticipantJoinActivityValue.Member>
103 {
104 new MeetingParticipantJoinActivityValue.Member
105 {
106 User = new Account { Id = "user1", Name = "Test User" },
107 Meeting = new MeetingParticipantJoinActivityValue.Meeting
108 {
109 InMeeting = true,
110 Role = Role.User
111 }
112 },
113
114 }
115 }
116 };
117
118 // Act
119 var result = attribute.Select(activity);
120
121 // Assert
122 Assert.True(result);
123 }
124
125 [Fact]
126 public void MeetingJoinAttribute_Select_ReturnsFalseForOtherActivities()
127 {
128 // Arrange
129 var attribute = new MeetingJoinAttribute();
130 var activity = new MessageActivity("hello world");
131
132 // Act
133 var result = attribute.Select(activity);
134
135 // Assert
136 Assert.False(result);
137 }
138
139
140 [Fact]
141 public async Task MeetingJoinAttribute_Controller_Call()
142 {
143 var activity = new MeetingParticipantJoinActivity
144 {
145 Value = new MeetingParticipantJoinActivityValue
146 {
147 Members = new List<MeetingParticipantJoinActivityValue.Member>
148 {
149 new MeetingParticipantJoinActivityValue.Member
150 {
151 User = new Account { Id = "user1", Name = "Test User" },
152 Meeting = new MeetingParticipantJoinActivityValue.Meeting
153 {
154 InMeeting = true,
155 Role = Role.User
156 }
157 },
158
159 }
160 }
161 };
162
163 var res = await _app.Process<TestPlugin>(_token, activity);
164
165 Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
166 Assert.Equal("meetingJoinMethod", _controller.MethodCalled);
167 }
168}