예제 #1
0
        public void ShouldGetMessagesFromUser()
        {
            //arrange
            var user = new User
            {
                Name    = "testCharUser",
                Picture = new byte[] {}
            };
            var    login    = "******";
            var    password = "******";
            var    title    = "chatTitle";
            var    pic      = new byte[] {};
            string msg1     = "TestText of msg";
            string msg2     = "TestText of msg2";

            //act
            var userRepository = new UsersRepository(ConnectionString);
            var resultUser1    = userRepository.Create(user, login, password);
            var resultUser2    = userRepository.Create(user, login + "1", password);
            var userIds        = new List <Guid> {
                resultUser1.Id, resultUser2.Id
            };

            _tempUsers.AddRange(userIds);
            var chatRepository = new ChatsRepository(ConnectionString);
            var resultChat     = chatRepository.Create(title, userIds, pic);

            _tempChats.Add(resultChat.Id);
            var messageRepository = new MessagesRepository(ConnectionString);
            var resultMsg1        = messageRepository.Send(msg1, resultUser1.Id, resultChat.Id);

            _tempMessages.Add(resultMsg1.Id);
            var resultMsg2 = messageRepository.Send(msg2, resultUser1.Id, resultChat.Id);

            _tempMessages.Add(resultMsg2.Id);
            var resultMsgs = messageRepository.GetMessagesFromUser(resultUser1.Id);

            //asserts
            Assert.AreEqual(true, resultMsgs.Any(m => m.Id == resultMsg1.Id));
            Assert.AreEqual(true, resultMsgs.Any(m => m.Id == resultMsg2.Id));
        }