microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Tests/Microsoft.Teams.Api.Tests/Clients/ConversationClientTests.cs
55lines · modecode
| 1 | using System.Net; |
| 2 | |
| 3 | using Microsoft.Teams.Api.Clients; |
| 4 | using Microsoft.Teams.Common.Http; |
| 5 | |
| 6 | using Moq; |
| 7 | |
| 8 | using static Microsoft.Teams.Api.Clients.ConversationClient; |
| 9 | |
| 10 | namespace Microsoft.Teams.Api.Tests.Clients; |
| 11 | |
| 12 | public class ConversationClientTests |
| 13 | { |
| 14 | [Fact] |
| 15 | public async Task ConversationClient_CreateAsync() |
| 16 | { |
| 17 | var createRequest = new CreateRequest() |
| 18 | { |
| 19 | IsGroup = true, |
| 20 | Bot = new Account() { Id = "botId" }, |
| 21 | Members = new List<Account>() { new Account() { Id = "userId" } }, |
| 22 | TopicName = "topicName" |
| 23 | }; |
| 24 | |
| 25 | var responseMessage = new HttpResponseMessage(); |
| 26 | responseMessage.Headers.Add("Custom-Header", "HeaderValue"); |
| 27 | var mockHandler = new Mock<IHttpClient>(); |
| 28 | mockHandler |
| 29 | .Setup(handler => handler.SendAsync<ConversationResource>(It.IsAny<IHttpRequest>(), It.IsAny<CancellationToken>())) |
| 30 | .ReturnsAsync(new HttpResponse<ConversationResource>() |
| 31 | { |
| 32 | Headers = responseMessage.Headers, |
| 33 | StatusCode = HttpStatusCode.OK, |
| 34 | Body = new ConversationResource |
| 35 | { |
| 36 | Id = "conversationId", |
| 37 | ServiceUrl = "https://serviceurl.com/" |
| 38 | } |
| 39 | }); |
| 40 | |
| 41 | string serviceUrl = "https://serviceurl.com/"; |
| 42 | var conversationClient = new ConversationClient(serviceUrl, mockHandler.Object); |
| 43 | |
| 44 | var reqBody = await conversationClient.CreateAsync(createRequest); |
| 45 | |
| 46 | Assert.Equal(serviceUrl, reqBody.ServiceUrl); |
| 47 | |
| 48 | string expecteUrl = "https://serviceurl.com/v3/conversations"; |
| 49 | HttpMethod expectedMethod = HttpMethod.Post; |
| 50 | mockHandler.Verify(x => x.SendAsync<ConversationResource>( |
| 51 | It.Is<IHttpRequest>(arg => arg.Url == expecteUrl && arg.Method == expectedMethod), |
| 52 | It.IsAny<CancellationToken>()), |
| 53 | Times.Once); |
| 54 | } |
| 55 | } |