Beispiel #1
0
        public IActionResult OnGet()
        {
            var repo = new ProfilesRepository(_context);

            ProfileViewModel = repo.CreateProfile();
            return(Page());
        }
        public void ShouldStartChatWithUser()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };
            const string chatName          = "UserChat";
            var          profileRepository = new ProfilesRepository(Constants.Constants.ConnectionString);
            var          result            = profileRepository.CreateProfile(profile);

            _tempUsers.Add(result.Id);
            var chatRepository = new ChatsRepository(Constants.Constants.ConnectionString, profileRepository);
            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 userChats = profileRepository.GetProfileChats(profile.Id);

            Assert.AreEqual(chatName, chat.ChatName);
            Assert.AreEqual(profile.Id, chat.ChatMembers.Single());
            var chats = userChats as IList <Chat> ?? userChats.ToList();

            Assert.AreEqual(chat.ChatId, chats.Single().ChatId);
            Assert.AreEqual(chat.ChatName, chats.Single().ChatName);
        }
        public void ShouldDeleteProfile()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };

            var repository = new ProfilesRepository(Constants.Constants.ConnectionString);

            repository.CreateProfile(profile);

            repository.DeleteProfile(profile.Id);
            try
            {
                repository.GetProfile(profile.Id);
            }
            catch (Exception)
            {
            }
        }
Beispiel #4
0
        public void ShouldGetChat()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };

            const string chatName = "GetChat";

            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 resultChatById = chatRepository.GetChat(chat.ChatId);

            Assert.AreEqual(chat.ChatName, resultChatById.ChatName);
        }
Beispiel #5
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;
            }
        }
Beispiel #6
0
        public void ShouldDeleteChat()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };

            const string chatName = "DeleteChat";

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

            _tempUsers.Add(resProfile.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);

            chatRepository.DeleteChat(chat.ChatId);
            try
            {
                chatRepository.GetChat(chat.ChatId);
            }
            catch (Exception)
            {
            }
        }
        public void ShouldCreateUser()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };
            var repository = new ProfilesRepository(Constants.Constants.ConnectionString);
            var result     = repository.CreateProfile(profile);

            _tempUsers.Add(result.Id);
            Assert.AreEqual(profile.Login, result.Login);
            Assert.AreEqual(profile.Avatar, result.Avatar);
            Assert.AreEqual(profile.Password, result.Password);
            Assert.AreEqual(profile.Name, result.Name);
            Assert.AreEqual(profile.Surname, result.Surname);
        }
Beispiel #8
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)
            {
            }
        }
Beispiel #9
0
        public void ShouldGetProfileChats()
        {
            var profile = new Profile
            {
                Id       = Guid.NewGuid(),
                Login    = "******",
                Avatar   = Guid.NewGuid(),
                Password = "******",
                Name     = "odmin",
                Surname  = "odmin"
            };

            const string chatName1 = "ProfileChat#1";
            const string chatName2 = "ProfileChat#2";
            const string chatName3 = "ProfileChat#3";
            const string chatName4 = "ProfileChat#4";

            var profilesRepository = new ProfilesRepository(Constants.Constants.ConnectionString);
            var resProfile         = profilesRepository.CreateProfile(profile);

            _tempUsers.Add(resProfile.Id);

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

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

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

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

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

            var chat1 = chatRepository.CreateChat(chat1Before);
            var chat2 = chatRepository.CreateChat(chat2Before);
            var chat3 = chatRepository.CreateChat(chat3Before);
            var chat4 = chatRepository.CreateChat(chat4Before);

            _chats.Add(chat1.ChatId);
            _chats.Add(chat2.ChatId);
            _chats.Add(chat3.ChatId);
            _chats.Add(chat4.ChatId);

            var profileChats = profilesRepository.GetProfileChats(profile.Id).ToList();

            var ch = profileChats.Find(x => x.ChatId == chat1.ChatId);

            Assert.AreEqual(chat1.ChatId, ch.ChatId);
            Assert.AreEqual(chatName1, ch.ChatName);

            ch = profileChats.Find(x => x.ChatId == chat2.ChatId);
            Assert.AreEqual(chat2.ChatId, ch.ChatId);
            Assert.AreEqual(chatName2, ch.ChatName);

            ch = profileChats.Find(x => x.ChatId == chat3.ChatId);
            Assert.AreEqual(chat3.ChatId, ch.ChatId);
            Assert.AreEqual(chatName3, ch.ChatName);

            ch = profileChats.Find(x => x.ChatId == chat4.ChatId);
            Assert.AreEqual(chat4.ChatId, ch.ChatId);
            Assert.AreEqual(chatName4, ch.ChatName);
        }