Ejemplo n.º 1
0
        /// <summary>
        /// Override de OnConnectedAsync
        /// Este metodo e chamado quando e estabelecida uma conexão ao hub e
        /// adiciona a conexão à BD
        /// </summary>
        /// <returns>Retorna um callback UserConnected com o id de conexão</returns>
        public override async Task OnConnectedAsync()
        {
            try
            {
                await Clients.All.SendAsync("UserConnected", Context.ConnectionId);

                int?userId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)Context.User.Identity);
                if (userId == null)
                {
                    throw new Exception("O utilizador não existe!");
                }

                ChatDAO chatDao = new ChatDAO(_connection);

                if (chatDao.GetChatConnectionFromUserId((int)userId) == null)
                {
                    chatDao.AddChatHubConnection((int)userId, Context.ConnectionId);
                }
                else
                {
                    chatDao.UpdateChatHubConnection((int)userId, Context.ConnectionId);
                }

                await base.OnConnectedAsync();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public PartialViewResult GroupChat()
        {
            var session = (UserLogin)Session[CommonConstants.USER_SESSION];
            var model   = new ChatDAO().GetAccounts(new ChatDAO().GetById(session.UserID).FACULTY_Id);

            return(PartialView(model));
        }
Ejemplo n.º 3
0
        public List <Message> GetMessages(int id)
        {
            ChatDAO        chatDAO     = new ChatDAO(_connection);
            List <Message> messageList = chatDAO.GetMessageList(id);

            return(messageList);
        }
Ejemplo n.º 4
0
        public ActionResult <bool> CreateChat(int matchId, int publicationId, string publicationName)
        {
            int?userId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

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

            UserDAO userDAO = new UserDAO(_connection);
            User    user    = userDAO.FindById(matchId);

            if (userId < 0)
            {
                return(UnprocessableEntity(new ErrorExceptionModel("Utilizador não existe!")));
            }

            Chat chat = new Chat();

            chat.UserId          = (int)userId;
            chat.PublicationId   = publicationId;
            chat.PublicationName = publicationName;
            ChatDAO chatDAO = new ChatDAO(_connection);

            chat.ChatId = chatDAO.CreateChatId();
            chatDAO.CreateChat(chat);

            chat.UserId = matchId;
            chatDAO.CreateChat(chat);

            return(Ok("Concluído!"));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Método para enviar uma mensagem privada para um utilizador,
        /// usando connection ID
        /// </summary>
        /// <param name="targetConnectionId">Connection ID de quem recebe a mensagem</param>
        /// <param name="senderConnectionId">Connection ID de quem envia a mensagem</param>
        /// <param name="message">Mensagem</param>
        /// <param name="time">Data e hora em que a mensagem foi enviada</param>
        /// <param name="targetId">Id do destinatário do chat</param>
        /// <param name="senderId">Id do remetente</param>
        /// <returns>Retorna uma task assincrona ReceivePrivateMessage,
        ///  para receber as mensagens enviadas para o socket</returns>
        public async Task SendPrivateMessage(string targetConnectionId, string senderConnectionId,
                                             string message, DateTime time, int targetId, int senderId)
        {
            try
            {
                ChatDAO chatDao = new ChatDAO(_connection);
                chatDao.AddMessage(targetConnectionId, senderConnectionId, message, time, targetId);

                int?chatId = chatDao.getChatIdWithTargetUser(senderId, targetId);

                if (chatId == null)
                {
                    throw new Exception("Não existe chat com os utilizadores correspondentes aos IDs!");
                }

                if (targetConnectionId != null)
                {
                    if (targetConnectionId.Length > 0)
                    {
                        await Clients.Clients(targetConnectionId, senderConnectionId).SendAsync("ReceivePrivateMessage", message, senderId);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 6
0
        public ActionResult CreateChat(int matchId)
        {
            int?userId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (userId == null)
            {
                return(Unauthorized(new ErrorMessageModel("Utilizador não tem autorização ou não existe!")));
            }

            try
            {
                ChatDAO chatDAO = new ChatDAO(_connection);

                if (chatDAO.getChatIdWithTargetUser((int)userId, matchId) == null)
                {
                    Chat chat = new Chat();
                    chat.UserId = (int)userId;
                    chat.ChatId = chatDAO.CreateChatId();

                    chatDAO.CreateChat(chat);

                    chat.UserId = matchId;
                    chatDAO.CreateChat(chat);

                    return(Ok(new SuccessMessageModel("Chat criado!")));
                }

                return(Ok(new SuccessMessageModel("O Chat já existe!")));
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorMessageModel(e.Message)));
            }
        }
Ejemplo n.º 7
0
        public ActionResult <Message> getLastMessageFromChat(int id)
        {
            int?userId = ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)this.ControllerContext.HttpContext.User.Identity);

            if (userId == null)
            {
                return(Unauthorized(new ErrorMessageModel("Utilizador não tem autorização ou não existe!")));
            }

            try
            {
                ChatDAO chatDao = new ChatDAO(_connection);
                Message message = chatDao.GetLastMessageFromChat(id, (int)userId);

                if (message != null)
                {
                    return(Ok(message));
                }

                return(BadRequest(new ErrorMessageModel("Não existe connection ID!")));
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorMessageModel(e.Message)));
            }
        }
        // GET: Chat
        public PartialViewResult Index()
        {
            var session = (UserLogin)Session[CommonConstants.USER_SESSION];
            var model   = new ChatDAO().GetMessage();

            return(PartialView(model));
        }
        public void CanCreateChatIdTest()
        {
            ChatDAO chatDao = new ChatDAO(_connection);

            Assert.True(chatDao.CreateChatId() > 0);

            _fixture.Dispose();
        }
Ejemplo n.º 10
0
        public void LoadNotificationMessageWithUser(Guid?From, Guid?To)
        {
            var dao = new ChatDAO();

            // Call the broadcastMessage method to update clients.
            NotificationWithUser = dao.GetMessage().Where(x => x.MESSAGE_To == To && x.MESSAGE_From == From && x.MESSAGE_Status == false).Count();
            Clients.All.broadcastNotificationMessageWithUser(NotificationWithUser, From, To);
        }
Ejemplo n.º 11
0
        public void Send(Guid?From, Guid?To, string message, string type)
        {
            var dao = new ChatDAO();

            dao.CreateContent(dao.CreateMessage(From, To).MESSAGE_Id, message, type);
            // Call the broadcastMessage method to update clients.
            Clients.All.broadcastMessage(From, To, message, type);
        }
Ejemplo n.º 12
0
 public ChatController(UserDAO _repos, ChatDAO _repos1, MessageDAO _repos3, IHubContext <ChatHub> hubContext, LogFactory _logFactory)
 {
     repos           = _repos;
     repos1          = _repos1;
     repos3          = _repos3;
     logFactory      = _logFactory;
     log             = logFactory.GetLogger();
     this.hubContext = hubContext;
 }
Ejemplo n.º 13
0
        public void RemoveNotification(Guid?To, Guid?From)
        {
            var dao = new ChatDAO();

            dao.ChangeStatus(To, From);
            NotificationWithUser = dao.GetMessage().Where(x => x.MESSAGE_To == To && x.MESSAGE_From == From && x.MESSAGE_Status == false).Count();
            Notification         = dao.GetMessage().Where(x => x.MESSAGE_To == To && x.MESSAGE_Status == false).Count();
            Clients.All.broadcastNotification(Notification, To);
        }
Ejemplo n.º 14
0
        //[Authorize(Roles = "M8,EMPLOYER")]
        public async Task <IActionResult> SendMessage(Message message)
        {
            //Enviar a msg em tempo real
            await _chatHub.Clients.Group(message.ChatId.ToString()).SendAsync("ReceiveGroupMessage", message.SenderId.ToString(), message.MessageSend);

            //Adicionar a mensagem a DB
            ChatDAO chatDAO   = new ChatDAO(_connection);
            bool    addedToDb = chatDAO.AddMessage(message);

            return(Ok("Resultado: " + addedToDb));
        }
Ejemplo n.º 15
0
        public void CanVerifyIfUserIsNotFromChatTest()
        {
            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();

            Chat chat = new Chat();

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

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

            bool user1IsFromChat = chatDao.IsUserFromChat(999999999, returned.Id);
            bool user2IsFromChat = chatDao.IsUserFromChat(999999999, returnedMate.Id);

            Assert.False(user1IsFromChat);
            Assert.False(user2IsFromChat);

            _fixture.Dispose();
        }
        public void CanUpdateChatHubConnectionTest()
        {
            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);

            chatDao.AddChatHubConnection(returned.Id, "connection1");
            chatDao.AddChatHubConnection(returnedMate.Id, "connection2");

            chatDao.UpdateChatHubConnection(returned.Id, "connection1Replaced");
            chatDao.UpdateChatHubConnection(returnedMate.Id, "connection2Replaced");

            ChatConnection connection1 = chatDao.GetChatConnectionFromUserId(returned.Id);
            ChatConnection connection2 = chatDao.GetChatConnectionFromUserId(returnedMate.Id);

            Assert.Equal("connection1Replaced", connection1.Connection);
            Assert.Equal(returned.Id, connection1.UserId);
            Assert.Equal("connection2Replaced", connection2.Connection);
            Assert.Equal(returnedMate.Id, connection2.UserId);

            _fixture.Dispose();
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Override de OnDisconnectedAsync
        /// Este metodo e chamado quando deixa de esistir uma conexão ao hub e
        /// remove a conexão da BD
        /// </summary>
        /// <returns>Retorna uma task assincrona UserDisconnected com o id de conexão</returns>
        public override async Task OnDisconnectedAsync(Exception ex)
        {
            try
            {
                await Clients.All.SendAsync("UserDisconnected", Context.ConnectionId);

                int     userId  = (int)ClaimHelper.GetIdFromClaimIdentity((ClaimsIdentity)Context.User.Identity);
                ChatDAO chatDao = new ChatDAO(_connection);
                chatDao.DeleteChatHubConnection(Context.ConnectionId);

                await base.OnDisconnectedAsync(ex);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public void ReturnExceptionCreatingChatWithUserId0Test()
        {
            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();

            Chat chat = new Chat();

            chat.UserId = 0;
            chat.ChatId = chatId;

            Assert.Throws <Exception>(() => chatDao.CreateChat(chat));

            _fixture.Dispose();
        }
Ejemplo n.º 20
0
        public ActionResult <List <Message> > GetMessages(int chatId)
        {
            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);
                List <Message> messageList = chatDAO.GetMessageList(chatId, (int)loggedUser);
                return(Ok(messageList));
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorMessageModel(e.Message)));
            }
        }
Ejemplo n.º 21
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));
            }
        }
Ejemplo n.º 22
0
        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();
        }
Ejemplo n.º 23
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();
        }
Ejemplo n.º 24
0
        public void CanAddMessageTest()
        {
            IEmployerDAO <Employer> employerDAO = new EmployerDAO(_connection);
            Employer testEmployerC = new Employer();

            testEmployerC.FirstName   = "Ema";
            testEmployerC.LastName    = "Coelho";
            testEmployerC.UserName    = "******";
            testEmployerC.Password    = "******";
            testEmployerC.Email       = "*****@*****.**";
            testEmployerC.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            testEmployerC.Address     = "Lousada";

            // Employe a utilizar
            Employer returnedEmployer = employerDAO.Create(testEmployerC);

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

            Mate firstMate = new Mate();

            firstMate.FirstName   = "Marcelddo";
            firstMate.LastName    = "Carvalho";
            firstMate.UserName    = "******";
            firstMate.Password    = "******";
            firstMate.Email       = "*****@*****.**";
            firstMate.Description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            firstMate.Address     = "Sra. Aparecida, Lousada";
            firstMate.Categories  = new[] { Categories.CLEANING, Categories.ELECTRICITY };
            firstMate.Rank        = Ranks.MATE;
            firstMate.Range       = 50;


            Mate returnMate = MateDAO.Create(firstMate);

            ChatDAO chatDAO = new ChatDAO(_connection);

            chatDAO.AddChatHubConnection(returnedEmployer.Id, "connection1");
            chatDAO.AddChatHubConnection(returnMate.Id, "connection2");

            int chatId = chatDAO.CreateChatId();

            Chat chat = new Chat();

            chat.ChatId = chatId;
            chat.UserId = returnedEmployer.Id;
            chatDAO.CreateChat(chat);
            chat.UserId = returnMate.Id;
            chatDAO.CreateChat(chat);


            ChatConnection connect1 = chatDAO.GetChatConnectionFromUserId(returnedEmployer.Id);
            ChatConnection connect2 = chatDAO.GetChatConnectionFromUserId(returnMate.Id);

            String MessageSend  = "message test";
            String MessageSend2 = "message test 2";

            bool addedToDb1 = chatDAO.AddMessage(connect1.Connection, connect2.Connection, MessageSend, DateTime.Now, returnedEmployer.Id);
            bool addedToDb2 = chatDAO.AddMessage(connect2.Connection, connect1.Connection, MessageSend2, DateTime.Now, returnMate.Id);

            Assert.True(addedToDb1);
            Assert.True(addedToDb2);

            _fixture.Dispose();
        }
Ejemplo n.º 25
0
 public HomeController(UserDAO _repos, ChatDAO _repos1)
 {
     repos  = _repos;
     repos1 = _repos1;
 }
Ejemplo n.º 26
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();
        }
Ejemplo n.º 27
0
 public ChatRepository(IConfigProvider configProvider)
 {
     chatDAO = new ChatDAO(configProvider);
     mapper  = new ModelsMapper();
 }