public void GetAddRemoveMembers() { CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(TestEnvironment.ConnectionString); Response <CommunicationUser> threadCreator = communicationIdentityClient.CreateUser(); Response <CommunicationUser> threadMember2 = communicationIdentityClient.CreateUser(); Response <CommunicationUser> threadMember3 = communicationIdentityClient.CreateUser(); string userToken = communicationIdentityClient.IssueToken(threadCreator.Value, new[] { CommunicationTokenScope.Chat }).Value.Token; string endpoint = TestEnvironment.ChatApiUrl(); ChatClient chatClient = new ChatClient( new Uri(endpoint), new CommunicationUserCredential(userToken)); var chatThreadMember = new ChatThreadMember(new CommunicationUser(threadCreator.Value.Id)) { DisplayName = "UserDisplayName", ShareHistoryTime = DateTime.MinValue }; ChatThreadClient chatThreadClient = chatClient.CreateChatThread(topic: "Hello world!", members: new[] { chatThreadMember }); Pageable <ChatThreadMember> allMembers = chatThreadClient.GetMembers(); foreach (ChatThreadMember member in allMembers) { Console.WriteLine($"{member.User.Id}:{member.DisplayName}:{member.ShareHistoryTime}"); } var members = new[] { new ChatThreadMember(threadCreator) { DisplayName = "display name thread creator" }, new ChatThreadMember(threadMember2) { DisplayName = "display name member 2" }, new ChatThreadMember(threadMember3) { DisplayName = "display name member 3" } }; chatThreadClient.AddMembers(members); chatThreadClient.RemoveMember(new CommunicationUser(threadMember2.Value.Id)); chatClient.DeleteChatThread(chatThreadClient.Id); }
public void E2E_ThreadCreateUpdateGetDelete_MemberAddUpdateRemove_MessageGetSendUpdate_NotificationTyping_ReadReceiptGetSend() { //arr CommunicationUser user1, user2, user3; string token1, token2, token3; CommunicationIdentityClient communicationIdentityClient = CreateInstrumentedCommunicationIdentityClient(); (user1, token1) = CreateUserAndToken(communicationIdentityClient); (user2, token2) = CreateUserAndToken(communicationIdentityClient); (user3, token3) = CreateUserAndToken(communicationIdentityClient); var topic = "Thread sync from C# sdk"; var messageContent = "This is message 1 content"; var updatedMessageContent = "This is message 1 content updated"; var displayNameMessage = "DisplayName sender message 1"; var updatedTopic = "Updated topic - C# sdk"; var members = new List <ChatThreadMember> { new ChatThreadMember(user1), new ChatThreadMember(user2) }; ChatClient chatClient = CreateInstrumentedChatClient(token1); ChatClient chatClient2 = CreateInstrumentedChatClient(token2); //act #region Snippet:Azure_Communication_Chat_Tests_E2E_InitializeChatThreadClient //@@ChatThreadClient chatThreadClient1 = chatClient.CreateChatThread("Thread topic", members); // Alternatively, if you have created a chat thread before and you have its threadId, you can create a ChatThreadClient instance using: //@@ChatThreadClient chatThreadClient2 = chatClient.GetChatThreadClient("threadId"); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_InitializeChatThreadClient ChatThreadClient chatThreadClient = CreateInstrumentedChatThreadClient(chatClient, topic, members); ChatThreadClient chatThreadClient2 = CreateInstrumentedChatThreadClient(chatClient, topic, members); #region Snippet:Azure_Communication_Chat_Tests_E2E_UpdateThread chatThreadClient.UpdateThread("Updated topic - C# sdk"); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_UpdateThread var threadId = chatThreadClient.Id; #region Snippet:Azure_Communication_Chat_Tests_E2E_GetChatThread ChatThread chatThread = chatClient.GetChatThread(threadId); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_GetChatThread #region Snippet:Azure_Communication_Chat_Tests_E2E_GetChatThreadsInfo Pageable <ChatThreadInfo> threads = chatClient.GetChatThreadsInfo(); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_GetChatThreadsInfo var threadsCount = threads.Count(); #region Snippet:Azure_Communication_Chat_Tests_E2E_SendMessage SendChatMessageResult sendChatMessageResult = chatThreadClient.SendMessage("This is message 1 content", ChatMessagePriority.High, displayNameMessage); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_SendMessage SendChatMessageResult sendChatMessageResult2 = chatThreadClient.SendMessage(messageContent, ChatMessagePriority.High, displayNameMessage); var messageId = sendChatMessageResult.Id; #region Snippet:Azure_Communication_Chat_Tests_E2E_GetMessage ChatMessage message = chatThreadClient.GetMessage(messageId); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_GetMessage #region Snippet:Azure_Communication_Chat_Tests_E2E_GetMessages Pageable <ChatMessage> messages = chatThreadClient.GetMessages(); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_GetMessages var getMessagesCount = messages.Count(); #region Snippet:Azure_Communication_Chat_Tests_E2E_UpdateMessage chatThreadClient.UpdateMessage(messageId, "This is message 1 content updated"); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_UpdateMessage Response <ChatMessage> actualUpdateMessage = chatThreadClient.GetMessage(messageId); #region Snippet:Azure_Communication_Chat_Tests_E2E_DeleteMessage chatThreadClient.DeleteMessage(messageId); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_DeleteMessage Pageable <ChatMessage> messagesAfterOneDeleted = chatThreadClient.GetMessages(); ChatMessage deletedChatMessage = messagesAfterOneDeleted.First(x => x.Id == messageId); #region Snippet:Azure_Communication_Chat_Tests_E2E_GetMembers Pageable <ChatThreadMember> chatThreadMembers = chatThreadClient.GetMembers(); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_GetMembers var chatThreadMembersCount = chatThreadMembers.Count(); var newMember = new ChatThreadMember(user3); #region Snippet:Azure_Communication_Chat_Tests_E2E_AddMembers chatThreadClient.AddMembers(members: new[] { newMember }); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_AddMembers Pageable <ChatThreadMember> chatThreadMembersAfterOneAdded = chatThreadClient.GetMembers(); var chatThreadMembersAfterOneAddedCount = chatThreadMembersAfterOneAdded.Count(); CommunicationUser memberToBeRemoved = user3; //Better name for the snippet #region Snippet:Azure_Communication_Chat_Tests_E2E_RemoveMember chatThreadClient.RemoveMember(user: memberToBeRemoved); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_RemoveMember Pageable <ChatThreadMember> chatThreadMembersAfterOneDeleted = chatThreadClient.GetMembers(); var chatThreadMembersAfterOneDeletedCount = chatThreadMembersAfterOneDeleted.Count(); Response typingNotificationResponse = chatThreadClient.SendTypingNotification(); #region Snippet:Azure_Communication_Chat_Tests_E2E_SendTypingNotification chatThreadClient.SendTypingNotification(); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_SendTypingNotification #region Snippet:Azure_Communication_Chat_Tests_E2E_SendReadReceipt chatThreadClient.SendReadReceipt(messageId); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_SendReadReceipt chatThreadClient.SendReadReceipt(sendChatMessageResult2.Id); #region Snippet:Azure_Communication_Chat_Tests_E2E_GetReadReceipts Pageable <ReadReceipt> readReceipts = chatThreadClient.GetReadReceipts(); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_GetReadReceipts var readReceiptsCount = readReceipts.Count(); #region Snippet:Azure_Communication_Chat_Tests_E2E_DeleteChatThread chatClient.DeleteChatThread(threadId); #endregion Snippet:Azure_Communication_Chat_Tests_E2E_DeleteChatThread //assert Assert.AreEqual(updatedTopic, chatThread.Topic); Assert.AreEqual(2, chatThread.Members.Count); Assert.AreEqual(messageContent, message.Content); Assert.AreEqual(displayNameMessage, message.SenderDisplayName); Assert.AreEqual(ChatMessagePriority.High, message.Priority); Assert.AreEqual(2, threadsCount); Assert.AreEqual(5, getMessagesCount); //Including all types Assert.AreEqual(updatedMessageContent, actualUpdateMessage.Value.Content); Assert.IsTrue(deletedChatMessage.DeletedOn.HasValue); Assert.AreEqual(2, chatThreadMembersCount); Assert.AreEqual(3, chatThreadMembersAfterOneAddedCount); Assert.AreEqual(2, chatThreadMembersAfterOneDeletedCount); Assert.AreEqual((int)HttpStatusCode.OK, typingNotificationResponse.Status); // TODO: Commenting out the assert below for now as it is flakey due to server-side delay; currently in investigation // Assert.AreEqual(1, readReceiptsCount); }