public void Clean()
        {
            var usersRepository    = new UsersRepository(_connectionString);
            var chatsRepository    = new ChatsRepository(_connectionString, usersRepository);
            var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository);

            foreach (var cm in _tempChatIdMemberIds)
            {
                chatsRepository.DeleteMember(cm.ChatId, cm.MemberId);
            }

            foreach (var messageId in _tmpMessages)
            {
                messagesRepository.DeleteMessage(messageId);
            }

            foreach (var chatId in _tmpChats)
            {
                chatsRepository.DeleteChat(chatId);
            }

            foreach (var userId in _tmpUsers)
            {
                usersRepository.DeleteUser(userId);
            }
        }
Esempio n. 2
0
        public void ShouldDeleteMessage()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };

            const string chatName = "SendChat";

            var usersRepository = new ProfilesRepository(Constants.Constants.ConnectionString);
            var result          = usersRepository.CreateProfile(profile);

            _tempUsers.Add(result.Id);

            var chatRepository = new ChatsRepository(Constants.Constants.ConnectionString, usersRepository);

            var chatBefore = new Chat
            {
                ChatId      = Guid.NewGuid(),
                ChatName    = chatName,
                ChatMembers = new List <Guid>(new[] { profile.Id })
            };

            var chat = chatRepository.CreateChat(chatBefore);

            _chats.Add(chat.ChatId);

            var messageRepository = new MessagesRepository(Constants.Constants.ConnectionString);

            var message = new Message
            {
                MessageId     = Guid.NewGuid(),
                ProfileId     = profile.Id,
                ChatId        = chat.ChatId,
                MessageText   = "Hello, world!",
                Date          = DateTime.Now,
                TimeToDestroy = 0,
                Attachment    = Guid.Empty
            };

            _messages.Add(message.MessageId);

            messageRepository.CreateMessage(message);

            messageRepository.DeleteMessage(message.MessageId);

            try
            {
                messageRepository.GetMessage(message.MessageId);
            }
            catch (Exception)
            {
                return;
            }
        }
        public void ShouldDeleteMessage()
        {
            //arrange
            var usersRepository    = new UsersRepository(_connectionString);
            var chatsRepository    = new ChatsRepository(_connectionString, usersRepository);
            var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository);
            var message            = messagesRepository.CreateMessage(_message);

            //act
            messagesRepository.DeleteMessage(message.Id);

            //assert
            Assert.ThrowsException <ArgumentException>(() => messagesRepository.GetMessage(message.Id));
        }
        public void ShouldDeleteMessage()
        {
            Chat chat = Create.Chat();

            Message message = new Message
            {
                UserFromID = chat.Members.ToArray()[0].UserID,
                ChatToID   = chat.ID,
                Text       = "TextMessage"
            };

            Guid messageID = messagesRepository.SendMessage(message).ID;

            messagesRepository.DeleteMessage(messageID);

            int countAfter = DB.Messages.Count(m => m.ID == messageID);

            Assert.AreEqual(0, countAfter);
        }
 public void Delete(int id)
 {
     _repository.DeleteMessage(id);
 }
 public void DeleteMessage(Guid id)
 => _messagesRepository.DeleteMessage(id);