Exemplo n.º 1
0
        public void ShouldAddDeleteMember()
        {
            var odminProfile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };

            var userProfile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "user",
                Surname  = "user"
            };

            const string chatName = "AddChat";

            var profilesRepository = new ProfilesRepository(Constants.Constants.ConnectionString);
            var resodminProfile    = profilesRepository.CreateProfile(odminProfile);
            var resUserProfile     = profilesRepository.CreateProfile(userProfile);

            _tempUsers.Add(resodminProfile.Id);
            _tempUsers.Add(resUserProfile.Id);

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

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

            var chat = chatRepository.CreateChat(chatBefore);

            _chats.Add(chat.ChatId);
            chatRepository.AddChatMember(resUserProfile.Id, chat.ChatId);

            var userChats = profilesRepository.GetProfileChats(resUserProfile.Id).ToList();

            Assert.AreEqual(chat.ChatId, userChats[0].ChatId);
            Assert.AreEqual(chat.ChatName, userChats[0].ChatName);


            chatRepository.DeleteChatMember(resUserProfile.Id, chat.ChatId);

            userChats = profilesRepository.GetProfileChats(resUserProfile.Id).ToList();
            try
            {
                Assert.AreEqual(chat.ChatId, userChats[0].ChatId);
                Assert.AreEqual(chat.ChatName, userChats[0].ChatName);
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }