private ChatClientOptions CreateChatClientOptionsWithCorrelationVectorLogs()
        {
            ChatClientOptions chatClientOptions = new ChatClientOptions();

            chatClientOptions.Diagnostics.LoggedHeaderNames.Add("MS-CV");
            return(InstrumentClientOptions(chatClientOptions));
        }
        public async Task AddParticipantsShouldExposePartialErrors()
        {
            //arrange
            var threadId = "19:[email protected]";
            var uri      = new Uri("https://localHostTest");
            var communicationTokenCredential = new CommunicationTokenCredential(ChatRecordedTestSanitizer.SanitizedUnsignedUserTokenValue);
            var mockResponse = new MockResponse(201);

            mockResponse.SetContent(AddParticipantsdWithErrorsApiResponsePayload);

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(mockResponse)
            };

            //act
            var chatClient = new ChatClient(uri, communicationTokenCredential, chatClientOptions);
            ChatThreadClient          chatThreadClient          = chatClient.GetChatThreadClient(threadId);
            AddChatParticipantsResult addChatParticipantsResult = await chatThreadClient.AddParticipantsAsync(new List <ChatParticipant>());

            //assert
            AsssertParticipantError(addChatParticipantsResult.Errors.InvalidParticipants.First(x => x.Code == "401"), "Authentication failed", "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345678");
            AsssertParticipantError(addChatParticipantsResult.Errors.InvalidParticipants.First(x => x.Code == "403"), "Permissions check failed", "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345679");
            AsssertParticipantError(addChatParticipantsResult.Errors.InvalidParticipants.First(x => x.Code == "404"), "Not found", "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345677");
            Assert.AreEqual(3, addChatParticipantsResult.Errors.InvalidParticipants.Count);
        }
        public async Task CreateChatThreadShouldExposePartialErrors()
        {
            //arrange
            var uri = new Uri("https://localHostTest");
            var communicationTokenCredential = new CommunicationTokenCredential(ChatRecordedTestSanitizer.SanitizedUnsignedUserTokenValue);
            var mockResponse = new MockResponse(201);

            mockResponse.SetContent(CreateChatThreadWithErrorsApiResponsePayload);

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(mockResponse)
            };

            //act
            var chatClient = new ChatClient(uri, communicationTokenCredential, chatClientOptions);
            CreateChatThreadResult createChatThreadResult = await chatClient.CreateChatThreadAsync("", new List <ChatParticipant>());

            //assert
            AsssertParticipantError(createChatThreadResult.Errors.InvalidParticipants.First(x => x.Code == "401"), "Authentication failed", "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345678");
            AsssertParticipantError(createChatThreadResult.Errors.InvalidParticipants.First(x => x.Code == "403"), "Permissions check failed", "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345679");
            AsssertParticipantError(createChatThreadResult.Errors.InvalidParticipants.First(x => x.Code == "404"), "Not found", "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345677");

            Assert.AreEqual(3, createChatThreadResult.Errors.InvalidParticipants.Count);
            Assert.AreEqual("8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c", createChatThreadResult.ChatThread.CreatedBy.Id);
            Assert.AreEqual("Topic for testing errors", createChatThreadResult.ChatThread.Topic);
            Assert.AreEqual("19:[email protected]", createChatThreadResult.ChatThread.Id);
        }
        public async Task OrderInGetReadReceiptsIteratorIsNotAltered()
        {
            //arrange
            var threadId         = "19:[email protected]";
            var baseSenderId     = "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-0464-274b-b274-5a3a0d00010";
            var baseReadOnDate   = DateTimeOffset.Parse("2020-12-15T00:00:00Z");
            var uri              = new Uri("https://localHostTest");
            var responseAllItems = new MockResponse(200);

            responseAllItems.SetContent(AllReadReceiptsApiResponsePayload);

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(responseAllItems)
            };

            //act
            var communicationTokenCredential = new CommunicationTokenCredential(ChatRecordedTestSanitizer.SanitizedUnsignedUserTokenValue);
            var chatClient = new ChatClient(uri, communicationTokenCredential, chatClientOptions);
            ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(threadId);

            AsyncPageable <ChatMessageReadReceipt> allReadReceipts = chatThreadClient.GetReadReceiptsAsync();

            //assert
            int idCounter = 0;

            await foreach (ChatMessageReadReceipt readReceipt in allReadReceipts)
            {
                idCounter++;
                Assert.AreEqual($"{idCounter}", readReceipt.ChatMessageId);
                Assert.AreEqual($"{baseSenderId}{idCounter}", readReceipt.SenderId);
                Assert.AreEqual(baseReadOnDate.AddSeconds(idCounter), readReceipt.ReadOn);
            }
            Assert.AreEqual(5, idCounter);
        }
示例#5
0
        public async Task OrderInGetMessagesIteratorIsNotAlteredByPaging()
        {
            //arrange
            var threadId = "19:[email protected]";
            var uri      = new Uri("https://localHostTest");

            var responseItemsPage1 = new MockResponse(200);

            responseItemsPage1.SetContent(Page1MessagesApiResponsePayload);

            var responseItemsPage2 = new MockResponse(200);

            responseItemsPage2.SetContent(Page2MessagesApiResponsePayload);

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(responseItemsPage1, responseItemsPage2)
            };

            //act
            var communicationTokenCredential = new CommunicationTokenCredential(ChatLiveTestBase.SanitizedUnsignedUserTokenValue);
            var chatClient = new ChatClient(uri, communicationTokenCredential, chatClientOptions);
            ChatThreadClient            chatThreadClient = chatClient.GetChatThreadClient(threadId);
            AsyncPageable <ChatMessage> allMessages      = chatThreadClient.GetMessagesAsync();

            //assert
            int pages               = 0;
            int idCounter           = 0;
            int textMessagesCounter = 0;

            await foreach (Page <ChatMessage> page in allMessages.AsPages(pageSizeHint: 4))
            {
                pages++;
                foreach (ChatMessage message in page.Values)
                {
                    idCounter++;
                    Assert.AreEqual($"{idCounter}", message.Id);
                    Assert.AreEqual($"{idCounter}", message.Version);
                    if (message.Type == "text")
                    {
                        textMessagesCounter++;
                        Assert.AreEqual($"Content for async message{idCounter}", message.Content.Message);
                    }
                }
            }
            Assert.AreEqual(2, pages);
            Assert.AreEqual(8, idCounter);
            Assert.AreEqual(5, textMessagesCounter);
        }
示例#6
0
        public async Task OrderInGetReadReceiptsIteratorIsNotAlteredByPaging()
        {
            //arrange
            var threadId       = "19:[email protected]";
            var uri            = new Uri("https://localHostTest");
            var baseSenderId   = "8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-0464-274b-b274-5a3a0d00010";
            var baseReadOnDate = DateTimeOffset.Parse("2020-12-15T00:00:00Z");

            var responseItemsPage1 = new MockResponse(200);

            responseItemsPage1.SetContent(Page1ReadReceiptsApiResponsePayload);

            var responseItemsPage2 = new MockResponse(200);

            responseItemsPage2.SetContent(Page2ReadReceiptsApiResponsePayload);

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(responseItemsPage1, responseItemsPage2)
            };

            //act
            var communicationTokenCredential = new CommunicationTokenCredential(ChatLiveTestBase.SanitizedUnsignedUserTokenValue);
            var chatClient = new ChatClient(uri, communicationTokenCredential, chatClientOptions);
            ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(threadId);
            AsyncPageable <ChatMessageReadReceipt> allreadReceipts = chatThreadClient.GetReadReceiptsAsync();

            //assert
            int pages     = 0;
            int idCounter = 0;

            //string? continuationToken = null;
            await foreach (Page <ChatMessageReadReceipt> page in allreadReceipts.AsPages(pageSizeHint: 3))
            {
                pages++;
                foreach (ChatMessageReadReceipt readReceipt in page.Values)
                {
                    idCounter++;
                    Assert.AreEqual($"{idCounter}", readReceipt.ChatMessageId);
                    Assert.AreEqual($"{baseSenderId}{idCounter}", ((UnknownIdentifier)readReceipt.Sender).Id);
                    Assert.AreEqual(baseReadOnDate.AddSeconds(idCounter), readReceipt.ReadOn);
                }
                //continuationToken = page.ContinuationToken;
            }
            Assert.AreEqual(2, pages);
            Assert.AreEqual(5, idCounter);
        }
示例#7
0
        private ChatClient CreateMockChatClient(int responseCode, string?responseContent = null)
        {
            var uri = new Uri("https://localHostTest");
            var communicationTokenCredential = new CommunicationTokenCredential(ChatLiveTestBase.SanitizedUnsignedUserTokenValue);
            var mockResponse = new MockResponse(responseCode);

            if (responseContent != null)
            {
                mockResponse.SetContent(responseContent);
            }

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(mockResponse)
            };

            return(new ChatClient(uri, communicationTokenCredential, chatClientOptions));
        }
        public async Task OrderInGetMessagesIteratorIsNotAltered()
        {
            //arrange
            var threadId         = "19:[email protected]";
            var uri              = new Uri("https://localHostTest");
            var responseAllItems = new MockResponse(200);

            responseAllItems.SetContent(_allMessagesApiResponsePayload);

            var chatClientOptions = new ChatClientOptions
            {
                Transport = new MockTransport(responseAllItems)
            };

            //act
            var communicationUserCredential         = new CommunicationUserCredential(ChatRecordedTestSanitizer.SanitizedUnsignedUserTokenValue);
            var chatThreadClient                    = new ChatThreadClient(threadId, uri, communicationUserCredential, chatClientOptions);
            AsyncPageable <ChatMessage> allMessages = chatThreadClient.GetMessagesAsync();

            //assert
            int idCounter           = 0;
            int textMessagesCounter = 0;

            await foreach (ChatMessage message in allMessages)
            {
                idCounter++;
                Assert.AreEqual($"{idCounter}", message.Id);
                Assert.AreEqual($"{idCounter}", message.Version);
                if (message.Type == "Text")
                {
                    textMessagesCounter++;
                    Assert.AreEqual($"Content for async message {idCounter}", message.Content);
                }
            }
            Assert.AreEqual(8, idCounter);
            Assert.AreEqual(5, textMessagesCounter);
        }