Beispiel #1
0
        public async Task <ApiResponse> GetWeChatSessionList()
        {
            var user          = HttpContext.DiscussionUser();
            var weChatAccount = _wechatAccountRepo.All().FirstOrDefault(wxa => wxa.UserId == user.Id);

            if (weChatAccount == null)
            {
                _logger.LogWarning("加载对话列表失败:{@ImportAttempt}", new { UserId = user.Id, user.UserName, Result = "未绑定微信号" });
                return(ApiResponse.NoContent(HttpStatusCode.BadRequest));
            }

            var messageList = await _chatyApiService.GetMessageList(weChatAccount.WxId);

            return(messageList == null
                ? ApiResponse.NoContent(HttpStatusCode.InternalServerError)
                : ApiResponse.ActionResult(messageList));
        }
        public async Task should_get_message_list()
        {
            var messageList = await _normalChatyApiService.GetMessageList("some_wx_id");

            Assert.Equal(3, _httpClient.RequestsSent.Count);
            Assert.Contains(_httpClient.RequestsSent, req => req.RequestUri.PathAndQuery == "/chat/list/some_wx_id");
            Assert.Contains(_httpClient.RequestsSent, req => req.RequestUri.PathAndQuery == "/chat/detail/some_wx_id/1556867244");
            Assert.Contains(_httpClient.RequestsSent, req => req.RequestUri.PathAndQuery == "/chat/detail/some_wx_id/1556867241");

            Assert.NotNull(messageList);
            Assert.Equal(2, messageList.Count);

            var firstMsg = messageList[0];

            Assert.Equal("1556867244", firstMsg.ChatId);
            Assert.Equal("text1...,text2...", string.Join(",", firstMsg.MessageSummaryList));

            var secondMsg = messageList[1];

            Assert.Equal("1556867241", secondMsg.ChatId);
            Assert.Equal("[文件],[链接]", string.Join(",", secondMsg.MessageSummaryList));
        }