public void service_must_return_correct_user_message_by_message_id_for_user()
        {
            var message     = DatabaseHelper.CreateValidMessage(DatabaseHelper.UserTest4);
            var userMessage = DatabaseHelper.CreateValidUserMessage(message, DatabaseHelper.UserTest4);

            _messageRepository.Create(message);
            _userMessageRepository.Create(userMessage);
            _unitOfWork.Commit();

            UserMessage userMessageFromService = _userMessageService.FindUserMessage(DatabaseHelper.UserTest4.Id, message.Id);

            Assert.AreEqual(userMessage.Id, userMessageFromService.Id, "Service must return correct user message by message id");
        }
        public MessageViewModel CreateMessageViewModel(Message message, Guid?timelineUserId, Guid watcherUserId, bool includeQutedMessage = false)
        {
            var author           = message.User;
            var messageViewModel = new MessageViewModel
            {
                MessageId          = message.Id,
                AuthorFullName     = author.FullName,
                AuthorGravatarHash = author.GravatarHash,
                AuthorId           = author.Id,
                AuthorUserName     = author.UserName,
                Mind              = message.Mind,
                Speech            = message.Speech,
                CreationDate      = message.CreationDate,
                IsAuthorOfMessage = message.User.Id == watcherUserId
            };

            if (includeQutedMessage && message.QuotedMessage != null)
            {
                messageViewModel.QuotedMessage = CreateMessageViewModel(message.QuotedMessage, timelineUserId, watcherUserId);
            }

            if (!string.IsNullOrWhiteSpace(message.Speech))
            {
                messageViewModel.HasSpeech         = true;
                messageViewModel.SpeechReadingTime = message.Speech.ReadingTime();
            }

            messageViewModel.AmountOfQuotes            = message.AmountOfQuotes;
            messageViewModel.AmountOfFavourites        = message.AmountOfFavourites;
            messageViewModel.AmountOfTransmitted       = message.AmountOfTransmitted;
            messageViewModel.AmountOfComments          = message.AmountOfComments;
            messageViewModel.WasMessageQuotedByUser    = _messageService.WasMessageQuotedByUser(message.Id, watcherUserId);
            messageViewModel.WasMessageCommentedByUser = _messageService.WasMessageCommentedByUser(message.Id, watcherUserId);
            messageViewModel.IsUserFavouriteMessage    = _messageFavouriteService.IsUserFavouriteMessage(watcherUserId, message.Id);

            UserMessage watcherUserMessage = _userMessageService.FindUserMessage(watcherUserId, message.Id);

            if (watcherUserMessage != null)
            {
                messageViewModel.IsMassageVisibleOnWatcherTimeline = true;
                messageViewModel.WasMessageTransmittedByUser       = watcherUserMessage.WasTransmitted;
                messageViewModel.UpdateSortingDateOnNewComment     = watcherUserMessage.UpdateSortingDateOnNewComment;
            }

            if (timelineUserId.HasValue)
            {
                UserMessage timelineUserMessage = _userMessageService.FindUserMessage(timelineUserId.Value, message.Id);
                if (timelineUserMessage != null && timelineUserMessage.TransmittedUserMessage != null)
                {
                    messageViewModel.IsTransmittedToUser     = true;
                    messageViewModel.TransmittedUserId       = timelineUserMessage.TransmittedUserMessage.User.Id;
                    messageViewModel.TransmittedUserFullName = timelineUserMessage.TransmittedUserMessage.User.FullName;
                    messageViewModel.TransmittedUserName     = timelineUserMessage.TransmittedUserMessage.User.UserName;
                }
            }

            if (message.Files != null && message.Files.Count > 0)
            {
                foreach (var file in message.Files)
                {
                    var fileViewModel = new FileViewModel {
                        FileUrl      = _fileService.GetUrlToFile(file),
                        ThumbnailUrl = _fileService.GetUrlToFileThumbnail(file)
                    };

                    messageViewModel.Files.Add(fileViewModel);
                }
            }

            return(messageViewModel);
        }