public async Task PostEmptyMessageException() { // We create the conversation or the dispose will throw not found var rand = Guid.NewGuid().ToString(); string[] usernames = _conversationId.Split('_'); var addConversationRequestBody = new AddConversationRequestBody { Participants = new List <string> { usernames[0], usernames[1] }, FirstMessage = new Dictionary <string, string> { { "Id", rand }, { "Text", "ae" }, { "SenderUsername", usernames[0] } } }; await _chatServiceClient.AddConversation(addConversationRequestBody); _messagesToCleanup.Add(rand); var id = Guid.NewGuid().ToString(); var addMessageRequestBody = new AddMessageRequestBody { Id = id, SenderUsername = "******", Text = "", }; var exception = await Assert.ThrowsAsync <ChatServiceException>( () => _chatServiceClient.AddMessage(_conversationId, addMessageRequestBody)); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task <AddConversationResponse> AddConversation(AddConversationRequestBody addConversationRequestBody) { var id = "m_" + addConversationRequestBody.Participants[0] + "_" + addConversationRequestBody.Participants[1]; var conversation = new Conversation { Id = id, Participants = addConversationRequestBody.Participants, LastModifiedUnixTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() }; var addConversationResponse = new AddConversationResponse { Id = addConversationRequestBody.Participants[0] + "_" + addConversationRequestBody.Participants[1], CreatedUnixTime = conversation.LastModifiedUnixTime }; using (_logger.BeginScope("{ConversationId}", id)) { var stopWatch = Stopwatch.StartNew(); await _conversationStore.AddConversation(conversation); _telemetryClient.TrackMetric("ConversationStore.AddConversation.Time", stopWatch.ElapsedMilliseconds); _telemetryClient.TrackEvent("ConversationCreated"); var message = new Message { Id = addConversationRequestBody.FirstMessage["Id"], Text = addConversationRequestBody.FirstMessage["Text"], SenderUsername = addConversationRequestBody.FirstMessage["SenderUsername"], UnixTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() }; await _messageStore.AddMessage(id.Remove(0, 2), message); return(addConversationResponse); } }
public async Task AddConversation(AddConversationRequestBody addConversationRequestBody) { string json = JsonConvert.SerializeObject(addConversationRequestBody); HttpResponseMessage response = await _httpClient.PostAsync($"api/conversations", new StringContent(json, Encoding.UTF8, "application/json")); await EnsureSuccessOrThrow(response); }
private static AddConversationRequestBody CreateRandomAddRequestBody(string username) { var rand = Guid.NewGuid().ToString(); var conversation = new AddConversationRequestBody { Participants = new List <string> { username, rand }, FirstMessage = new Dictionary <string, string> { { "Id", rand }, { "Text", "ae" }, { "SenderUsername", username } } }; return(conversation); }
public async Task <IActionResult> AddConversation([FromBody] AddConversationRequestBody requestBody) { var addConversationResponse = await _conversationService.AddConversation(requestBody); return(StatusCode(201, addConversationResponse)); }