public void ShouldGetMessage()
        {
            //arrange
            var usersRepository    = new UsersRepository(_connectionString);
            var chatsRepository    = new ChatsRepository(_connectionString, usersRepository);
            var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository);
            var createdMessage     = messagesRepository.CreateMessage(_message);

            _tmpMessages.Add(createdMessage.Id);

            //act
            var gottenMessage = messagesRepository.GetMessage(createdMessage.Id);

            //assert
            Assert.AreEqual(createdMessage.Text, gottenMessage.Text);
            Assert.AreEqual(createdMessage.IsSelfDestructing, gottenMessage.IsSelfDestructing);
            Assert.AreEqual(createdMessage.Date.ToString(CultureInfo.InvariantCulture), gottenMessage.Date.ToString(CultureInfo.InvariantCulture));
            if (createdMessage.Attachments.ElementAt(0).Length ==
                gottenMessage.Attachments.ElementAt(0).Length)
            {
                Assert.IsTrue(createdMessage.Attachments.ElementAt(0).
                              SequenceEqual(gottenMessage.Attachments.ElementAt(0)));
                Assert.IsTrue(createdMessage.Attachments.ElementAt(1).
                              SequenceEqual(gottenMessage.Attachments.ElementAt(1)));
            }
            else
            {
                Assert.IsTrue(createdMessage.Attachments.ElementAt(0).
                              SequenceEqual(gottenMessage.Attachments.ElementAt(1)));
                Assert.IsTrue(createdMessage.Attachments.ElementAt(1).
                              SequenceEqual(gottenMessage.Attachments.ElementAt(0)));
            }
        }
Ejemplo 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 ShouldCreateMessage()
        {
            //arrange
            var usersRepository    = new UsersRepository(_connectionString);
            var chatsRepository    = new ChatsRepository(_connectionString, usersRepository);
            var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository);

            //act
            var message = messagesRepository.CreateMessage(_message);

            _tmpMessages.Add(message.Id);

            //assert
            Assert.AreEqual(_message.Text, message.Text);
            Assert.AreEqual(_message.Date, message.Date);
            Assert.AreEqual(_message.Chat.Id, message.Chat.Id);
            Assert.AreEqual(_message.User.Id, message.User.Id);
        }
Ejemplo n.º 5
0
        public void Initialize()
        {
            var user1 = new User
            {
                FirstName = "Thomas",
                LastName  = "Anderson",
                Login     = "******",
                Password  = "******"
            };

            var user2 = new User
            {
                FirstName = "Smith",
                LastName  = "Smith",
                Login     = "******",
                Password  = "******"
            };

            var user3 = new User
            {
                FirstName = "Noname",
                LastName  = "Noname",
                Login     = "******",
                Password  = "******"
            };

            var usersRepository = new UsersRepository(_connectionString);

            _users = new List <User>
            {
                usersRepository.CreateUser(user1),
                usersRepository.CreateUser(user2),
                usersRepository.CreateUser(user3)
            };
            _tempUserIds.AddRange(_users.Select(u => u.Id));

            var chat = new Chat
            {
                Creater = _users[0],
                Members = new[] { _users[0], _users[1] },
                Name    = "ChatName"
            };

            var chatsRepository = new ChatsRepository(_connectionString, usersRepository);

            _chat = chatsRepository.CreateChat(chat);
            _tempChatIds.Add(_chat.Id);
            _tempChatIdMemberIds.AddRange(new[]
            {
                new ChatIdMemberId {
                    ChatId = _chat.Id, MemberId = _users[0].Id
                },
                new ChatIdMemberId {
                    ChatId = _chat.Id, MemberId = _users[1].Id
                }
            });

            var message1 = new Message
            {
                Chat = _chat,
                Date = DateTime.Now.ToUniversalTime(),
                IsSelfDestructing = false,
                Text        = "Message1",
                User        = _users[0],
                Attachments = new List <byte[]>
                {
                    Encoding.UTF8.GetBytes("Hello"),
                    Encoding.UTF8.GetBytes("World")
                }
            };

            var message2 = new Message
            {
                Chat = _chat,
                Date = DateTime.Now.ToUniversalTime(),
                IsSelfDestructing = false,
                Text = "Message2",
                User = _users[0]
            };

            var messagesRepository = new MessagesRepository(_connectionString, usersRepository, chatsRepository);

            _messages = new List <Message>
            {
                messagesRepository.CreateMessage(message1),
                messagesRepository.CreateMessage(message2)
            };
            _tempMessageIds.AddRange(_messages.Select(m => m.Id));
            _chat.Messages = _messages;
        }