public void AddMessageToConversation_ReturnCorrectMappedReadModel_WhereUserWhoAreGoingToReceiveThisMessage_WasNotSender()
        {
            //Arrange
            var saveModel = new ChatMessageSaveModel
            {
                AddresseeId = "addresseeTestId",
                SenderId    = "senderTestId",
                Content     = "test content",
            };

            var date = new DateTime(2016, 07, 06);
            var savedMessageDbModel = new ChatMessage
            {
                Author = new ApplicationUser {
                    Id = saveModel.SenderId, UserName = saveModel.SenderId
                },
                Date    = date,
                Content = saveModel.Content
            };

            this.conversationDbService.Setup(s => s.SaveMessage(It.IsAny <ChatMessage>())).Returns(savedMessageDbModel);

            //Act
            var messageReadModel = this.serviceUnderTest.AddMessageToConversation(saveModel);

            //Assert
            Assert.NotNull(messageReadModel);
            Assert.False(messageReadModel.UserWasSender);
            Assert.NotEmpty(messageReadModel.MessageContent);
            Assert.NotEmpty(messageReadModel.MessageHeader);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves message in db and returns message read model
        /// </summary>
        /// <param name="chatMessageSaveModel">Model with message parameters</param>
        /// <returns>Message read model</returns>
        public ChatMessageReadModel AddMessageToConversation(ChatMessageSaveModel chatMessageSaveModel)
        {
            UpdateConversationIfIsMarkedAsDeleted(chatMessageSaveModel.ConversationId);

            var messageDbModel = new ChatMessage();

            messageDbModel.AuthorId       = chatMessageSaveModel.SenderId;
            messageDbModel.ConversationId = chatMessageSaveModel.ConversationId;
            messageDbModel.Content        = chatMessageSaveModel.Content;
            messageDbModel.Date           = DateTime.Now;

            messageDbModel = this.conversationDbService.SaveMessage(messageDbModel);

            return(MapChatMessageToReadModel(chatMessageSaveModel.AddresseeId, messageDbModel));
        }
Exemplo n.º 3
0
        public async Task <bool> SendHelloMessageToNewUser(string addresseeId)
        {
            var isSent = false;
            var sender = await applicationUserManager.GetUserByEmail(appConfiguration.AutomaticChatMessagesSenderEmail);

            if (sender != null)
            {
                var conversation = await GetConversationInfoModel(sender.Id, addresseeId);

                var helloMessage = new ChatMessageSaveModel
                {
                    ConversationId = conversation.ConversationId,
                    SenderId       = sender.Id,
                    AddresseeId    = addresseeId,
                    Content        = Properties.Resources.helloMSH
                };

                AddMessageToConversation(helloMessage);
                isSent = true;
            }

            return(isSent);
        }