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 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(); }