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/MeetingLeaveEventTests.cs

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