Ejemplo n.º 1
0
        public async Task ShouldNotSendToBlockedUser()
        {
            var firedEventsCount = 0;
            var senderId         = 1;
            var blockerId        = 2;
            var conversationId   = 1;
            var sender           = new User()
            {
                Id = senderId
            };
            var conversation = new Conversation()
            {
                Id = conversationId
            };
            var conversationUsers = new List <ConversationUser>()
            {
                new ConversationUser()
                {
                    ConversationId = conversationId,
                    UserId         = senderId
                },
                new ConversationUser()
                {
                    ConversationId = conversationId,
                    UserId         = blockerId
                }
            };

            var blackListRepository = new TestRepository <BlackList>(new List <BlackList>()
            {
                new BlackList()
                {
                    InitiatorId = blockerId, BlockedId = senderId
                }
            });
            var messageRepository    = new TestRepository <Message>();
            var attachmentRepository = new TestRepository <Attachment>();

            var timeProvider = new TestTimeProvider();
            var attachmentContentProvider = new TestAttachmentContentProvider();

            var blackListService        = new BlackListService(blackListRepository, _mapper);
            var conversationUserService = new ConversationUserService(new TestRepository <ConversationUser>(conversationUsers), _mapper);

            var messageService = new MessageService(messageRepository,
                                                    attachmentRepository,
                                                    timeProvider,
                                                    attachmentContentProvider,
                                                    blackListService,
                                                    conversationUserService,
                                                    _mapper);

            messageService.OnMessageSent += (m) => firedEventsCount++;


            await messageService.SendMessageAsync(sender.Id, conversation.Id, "test", new AttachmentDto[] { new AttachmentDto {
                                                                                                                Id = 1, MessageId = 1
                                                                                                            } });

            Assert.Empty(messageRepository.All());
            Assert.Empty(attachmentRepository.All());
            Assert.Equal(0, firedEventsCount);
        }