public async Task ShouldDeleteMessage() { var firedEventsCount = 0; var blackListRepository = new TestRepository <BlackList>(); var messageRepository = new TestRepository <Message>(); var conversationRepository = new TestRepository <Conversation>(); var conversationUserRepository = new TestRepository <ConversationUser>(); var attachmentRepository = new TestRepository <Attachment>(); var timeProvider = new TestTimeProvider(); var attachmentContentProvider = new TestAttachmentContentProvider(); var conversationUserService = new ConversationUserService(conversationUserRepository, _mapper); var blackListService = new BlackListService(blackListRepository, _mapper); var messageService = new MessageService(messageRepository, attachmentRepository, timeProvider, attachmentContentProvider, blackListService, conversationUserService, _mapper); var sender = new User() { Id = 1 }; var conversation = new Conversation() { Id = 1 }; messageService.OnMessagesDeleted += (m) => firedEventsCount++; var result = await messageService.SendMessageAsync(sender.Id, conversation.Id, "test", new AttachmentDto[] { new AttachmentDto { Id = 1, MessageId = 0 } }); await messageService.DeleteByIdsAsync(sender.Id, result.Entity.Id); Assert.Empty(messageRepository.All()); Assert.Empty(attachmentRepository.All()); Assert.Equal(1, firedEventsCount); }
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); }