public ActionResult <Chat[]> GetChatsArray()
        {
            int?id = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (id == null)
            {
                return(Unauthorized(new ErrorExceptionModel("Utilizador não tem autorização!")));
            }

            ChatDAO chatDAO = new ChatDAO(_connection);

            Chat[] chatArray = chatDAO.GetChats((int)id);

            return(chatArray);
        }
Example #2
0
        public ActionResult <Chat[]> GetChatsArray()
        {
            int?loggedUser = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (loggedUser == null)
            {
                return(Unauthorized("Utilizador não autorizado ou inexistente!"));
            }

            try
            {
                ChatDAO chatDAO   = new ChatDAO(_connection);
                Chat[]  chatArray = chatDAO.GetChats((int)loggedUser);

                return(Ok(chatArray));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public void CanGetChatsTest()
        {
            IEmployerDAO <Employer> EmployerDAO = new EmployerDAO(_connection);
            Employer testEmployer = new Employer();

            testEmployer.FirstName   = "Marcelo";
            testEmployer.LastName    = "Carvalho";
            testEmployer.UserName    = "******";
            testEmployer.Password    = "******";
            testEmployer.Email       = "*****@*****.**";
            testEmployer.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployer.Address     = "Lixa";

            Employer returned = EmployerDAO.Create(testEmployer);

            IMateDAO <Mate> MateDAO  = new MateDAO(_connection);
            Mate            testMate = new Mate();

            testMate.FirstName   = "Miguel";
            testMate.LastName    = "Dev";
            testMate.UserName    = "******";
            testMate.Password    = "******";
            testMate.Email       = "*****@*****.**";
            testMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testMate.Address     = "Figueiró";
            testMate.Categories  = new[] { Categories.CLEANING, Categories.PLUMBING };
            testMate.Rank        = Ranks.SUPER_MATE;
            testMate.Range       = 20;

            Mate returnedMate = MateDAO.Create(testMate);

            ChatDAO chatDao = new ChatDAO(_connection);

            int chatId  = chatDao.CreateChatId();
            int chatId2 = chatDao.CreateChatId();

            Chat chat = new Chat();

            chat.UserId = returned.Id;
            chat.ChatId = chatId;

            chatDao.CreateChat(chat);
            chat.UserId = returnedMate.Id;
            chatDao.CreateChat(chat);

            Chat chat2 = new Chat();

            chat2.UserId = returned.Id;
            chat2.ChatId = chatId2;

            chatDao.CreateChat(chat2);
            chat2.UserId = returnedMate.Id;
            chatDao.CreateChat(chat2);

            Chat[] user1ChatArray = chatDao.GetChats(returned.Id);
            Chat[] user2ChatArray = chatDao.GetChats(returnedMate.Id);

            Assert.Equal(2, user1ChatArray.Length);
            Assert.Equal(2, user2ChatArray.Length);

            Assert.Equal(chatId, user1ChatArray[0].ChatId);
            Assert.Equal(returnedMate.Id, user1ChatArray[0].UserId);
            Assert.Equal(chatId, user2ChatArray[0].ChatId);
            Assert.Equal(returned.Id, user2ChatArray[0].UserId);

            Assert.Equal(chatId2, user1ChatArray[1].ChatId);
            Assert.Equal(returnedMate.Id, user1ChatArray[1].UserId);
            Assert.Equal(chatId2, user2ChatArray[1].ChatId);
            Assert.Equal(returned.Id, user2ChatArray[1].UserId);

            _fixture.Dispose();
        }
Example #4
0
        public void CanGetChatsFromDb()
        {
            UserDAO userDAO   = new UserDAO(_connection);
            User    testUser1 = new User();

            testUser1.Email     = "*****@*****.**";
            testUser1.Password  = "******";
            testUser1.FirstName = "Ema";
            testUser1.LastName  = "Coelho";
            testUser1.Password  = "******";
            testUser1.Image     = "ImageLocation";
            Address adr = new Address();

            adr.PostalCode         = "4615-423";
            adr.Street             = "Rua de Real";
            adr.StreetNumber       = 55;
            adr.District           = "Porto";
            adr.Country            = "Portugal";
            testUser1.Localization = adr.ToString();

            //User 1 a utilizar
            User returnedUser = userDAO.Create(testUser1);

            User testUser2 = new User();

            testUser2.Email     = "*****@*****.**";
            testUser2.Password  = "******";
            testUser2.FirstName = "Ema";
            testUser2.LastName  = "Coelho";
            testUser2.Password  = "******";
            testUser2.Image     = "ImageLocation";
            Address adr2 = new Address();

            adr2.PostalCode        = "4615-423";
            adr2.Street            = "Rua de Real";
            adr2.StreetNumber      = 55;
            adr2.District          = "Porto";
            adr2.Country           = "Portugal";
            testUser2.Localization = adr2.ToString();

            //User 2 a utilizar
            User returnedUser2 = userDAO.Create(testUser2);

            Chat    chat    = new Chat();
            ChatDAO chatDAO = new ChatDAO(_connection);
            int     chatId  = chatDAO.CreateChatId();

            chat.ChatId = chatId;
            chat.UserId = returnedUser.Id;
            chatDAO.CreateChat(chat);
            chat.UserId = returnedUser2.Id;
            chatDAO.CreateChat(chat);

            Chat[] chatArrayEmploye = chatDAO.GetChats(returnedUser.Id);
            Chat[] chatArrayMate    = chatDAO.GetChats(returnedUser2.Id);

            Message message = new Message();

            message.ChatId      = chatId;
            message.MessageSend = "message test";
            message.SenderId    = returnedUser.Id;
            message.Time        = DateTime.Now;

            bool addedToDb = chatDAO.AddMessage(message);

            List <Message> returnMessages  = chatDAO.GetMessageList(chatId);
            Message        returnedMessage = returnMessages.First();

            Assert.Equal(message.ChatId, returnedMessage.ChatId);
            Assert.Equal(message.MessageSend, returnedMessage.MessageSend);
            Assert.Equal(message.SenderId, returnedMessage.SenderId);

            _fixture.Dispose();
        }
 public ChatsPageViewModel()
 {
     ChatList = chatDAO.GetChats();
 }
Example #6
0
        public void CanGetChatsBy_UserId()
        {
            UserDAO userDAO   = new UserDAO(_connection);
            User    testUser1 = new User();

            testUser1.Email     = "*****@*****.**";
            testUser1.Password  = "******";
            testUser1.FirstName = "Ema";
            testUser1.LastName  = "Coelho";
            testUser1.Password  = "******";
            testUser1.Image     = "ImageLocation";
            Address adr = new Address();

            adr.PostalCode         = "4615-423";
            adr.Street             = "Rua de Real";
            adr.StreetNumber       = 55;
            adr.District           = "Porto";
            adr.Country            = "Portugal";
            testUser1.Localization = adr.ToString();

            //User 1 a utilizar
            User returnedUser = userDAO.Create(testUser1);

            User testUser2 = new User();

            testUser2.Email     = "*****@*****.**";
            testUser2.Password  = "******";
            testUser2.FirstName = "Ema";
            testUser2.LastName  = "Coelho";
            testUser2.Password  = "******";
            testUser2.Image     = "ImageLocation";
            Address adr2 = new Address();

            adr2.PostalCode        = "4615-423";
            adr2.Street            = "Rua de Real";
            adr2.StreetNumber      = 55;
            adr2.District          = "Porto";
            adr2.Country           = "Portugal";
            testUser2.Localization = adr2.ToString();

            //User 2 a utilizar
            User returnedUser2 = userDAO.Create(testUser2);

            Chat    chat    = new Chat();
            ChatDAO chatDAO = new ChatDAO(_connection);
            int     chatId  = chatDAO.CreateChatId();

            chat.ChatId = chatId;
            chat.UserId = returnedUser.Id;
            chatDAO.CreateChat(chat);
            chat.UserId = returnedUser2.Id;
            chatDAO.CreateChat(chat);

            Chat[] chatArrayEmploye = chatDAO.GetChats(returnedUser.Id);
            Chat[] chatArrayMate    = chatDAO.GetChats(returnedUser2.Id);

            Assert.True(chatArrayEmploye.Length > 0);
            Assert.True(chatArrayMate.Length > 0);

            _fixture.Dispose();
        }