microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/close-pull-request

Branches

Tags

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

Clone

HTTPS

Download ZIP

Tests/Microsoft.Teams.Api.Tests/Clients/MeetingClientTests.cs

86lines · modecode

1using System.Net;
2
3using Microsoft.Teams.Api.Clients;
4using Microsoft.Teams.Api.Meetings;
5using Microsoft.Teams.Common.Http;
6
7using Moq;
8
9namespace Microsoft.Teams.Api.Tests.Clients;
10
11public class MeetingClientTests
12{
13 [Fact]
14 public async Task MeetingClient_GetByIdAsync()
15 {
16 var responseMessage = new HttpResponseMessage();
17 responseMessage.Headers.Add("Custom-Header", "HeaderValue");
18 var mockHandler = new Mock<IHttpClient>();
19 mockHandler
20 .Setup(handler => handler.SendAsync<Meeting>(It.IsAny<IHttpRequest>(), It.IsAny<CancellationToken>()))
21 .ReturnsAsync(new HttpResponse<Meeting>()
22 {
23 Headers = responseMessage.Headers,
24 StatusCode = HttpStatusCode.OK,
25 Body = new Meeting { Id = "meeting123" }
26 });
27
28 string serviceUrl = "https://serviceurl.com/";
29 string meetingId = "meeting123";
30 var meetingClient = new MeetingClient(serviceUrl, mockHandler.Object);
31
32 var result = await meetingClient.GetByIdAsync(meetingId);
33
34 Assert.Equal("meeting123", result.Id);
35
36 string expectedUrl = "https://serviceurl.com/v1/meetings/meeting123";
37 HttpMethod expectedMethod = HttpMethod.Get;
38 mockHandler.Verify(x => x.SendAsync<Meeting>(
39 It.Is<IHttpRequest>(arg => arg.Url == expectedUrl && arg.Method == expectedMethod),
40 It.IsAny<CancellationToken>()),
41 Times.Once);
42 }
43
44 [Fact]
45 public async Task MeetingClient_GetParticipantAsync()
46 {
47 var responseMessage = new HttpResponseMessage();
48 responseMessage.Headers.Add("Custom-Header", "HeaderValue");
49 var mockHandler = new Mock<IHttpClient>();
50 mockHandler
51 .Setup(handler => handler.SendAsync<MeetingParticipant>(It.IsAny<IHttpRequest>(), It.IsAny<CancellationToken>()))
52 .ReturnsAsync(new HttpResponse<MeetingParticipant>()
53 {
54 Headers = responseMessage.Headers,
55 StatusCode = HttpStatusCode.OK,
56 Body = new MeetingParticipant
57 {
58 Id = "participant1",
59 User = new Account { Id = "user1", Name = "John Doe" },
60 Role = "Presenter",
61 IsOrganizer = true,
62 JoinTime = DateTime.UtcNow
63 }
64 });
65
66 string serviceUrl = "https://serviceurl.com/";
67 string meetingId = "meeting123";
68 string participantId = "participant1";
69 var meetingClient = new MeetingClient(serviceUrl, mockHandler.Object);
70
71 var result = await meetingClient.GetParticipantAsync(meetingId, participantId);
72
73 Assert.Equal("participant1", result.Id);
74 Assert.Equal("user1", result.User?.Id);
75 Assert.Equal("John Doe", result.User?.Name);
76 Assert.Equal("Presenter", result.Role);
77 Assert.True(result.IsOrganizer);
78
79 string expectedUrl = "https://serviceurl.com/v1/meetings/meeting123/participants/participant1";
80 HttpMethod expectedMethod = HttpMethod.Get;
81 mockHandler.Verify(x => x.SendAsync<MeetingParticipant>(
82 It.Is<IHttpRequest>(arg => arg.Url == expectedUrl && arg.Method == expectedMethod),
83 It.IsAny<CancellationToken>()),
84 Times.Once);
85 }
86}