public void DeleteMessage_ShouldReturnAMessage()
        {
            //Arrange
            Message returnMessage = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                var conversation            = msService.CreateConversation(testAuthUserId, testContactUserId, testContactUsername);
                db.SaveChanges();
                Message message = new Message
                {
                    ConversationOfMessage = conversation,
                    OutgoingMessage       = true,
                    MessageContent        = "testContent2",
                    CreatedDate           = DateTime.Now
                };

                message = msService.SaveMessageToDatabase(message);
                db.SaveChanges();
                var foundMessage = db.Messages.Where(m => m.MessageContent.Equals("testContent2")).FirstOrDefault();
                returnMessage = msService.DeleteMessage(foundMessage.Id);
                db.SaveChanges();


                //Assert
                Assert.NotNull(returnMessage);
            }
        }
Ejemplo n.º 2
0
        public void AddUserToFriendList_ShouldReturnAFriendUserNoExceptionThrown()
        {
            //Arrange
            FriendRelationship friendUser = null;

            //Act
            MessengerManager messengerManager = new MessengerManager();
            bool             isFriend;

            using (DatabaseContext db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                isFriend = msService.IsFriend(testAuthUserId, testContactUserId);
                if (isFriend == true)
                {
                    messengerManager.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
                }
                db.SaveChanges();
            }

            friendUser = messengerManager.AddUserFriendList(testAuthUserId, testContactUsername);

            //Assert
            Assert.NotNull(friendUser);
        }
        public void GetRecentMessageFromConversation_ShouldReturnAMessage()
        {
            //Arrange
            Message expected = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                var conversation            = msService.CreateConversation(testAuthUserId, testContactUserId, testContactUsername);
                db.SaveChanges();
                var message = new Message
                {
                    ConversationOfMessage = conversation,
                    OutgoingMessage       = true,
                    MessageContent        = "testContent2",
                    CreatedDate           = DateTime.Now
                };

                message = msService.SaveMessageToDatabase(message);
                db.SaveChanges();
                var foundConversation = db.Conversations.Where(c => c.UserId == testAuthUserId && c.ContactUserId == testContactUserId).FirstOrDefault();

                expected = msService.GetMostRecentMessageConversation(foundConversation.Id);
            }

            //Assert
            Assert.NotNull(expected);
        }
        public void SaveMessageToDatabase_ShouldReturnAMessage()
        {
            //Arrange
            Message message = new Message
            {
                ConversationId  = conversationIdForTest,
                OutgoingMessage = true,
                MessageContent  = "testContent",
                CreatedDate     = DateTime.Now
            };
            Message returnMessage = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                try
                {
                    returnMessage = msService.SaveMessageToDatabase(message);
                    db.SaveChanges();
                }

                catch (DbUpdateException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            //Assert
            Assert.NotNull(returnMessage);
        }
        public void GetAllConversation_ShouldReturnACollectionOfConversation()
        {
            //Arrange
            IEnumerable <Conversation> conversations = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                msService.CreateConversation(testAuthUserId, testContactUserId, testContactUsername);
                db.SaveChanges();
                conversations = msService.GetAllConversation(testAuthUserId);
            }

            //Assert
            Assert.NotNull(conversations);
        }
        public void GetaConversationById_ShouldReturnAConversation()
        {
            //Arrange
            Conversation conversation = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                var returnConversation      = msService.CreateConversation(testAuthUserId, testContactUserId, testContactUsername);
                db.SaveChanges();
                conversation = msService.GetConversationFromId(returnConversation.Id);
            }

            //Assert
            Assert.NotNull(conversation);
        }
        public void ChekifUsersAreFriend_ShouldReturnTrue()
        {
            //Arrange
            bool fr = false;


            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                msService.AddContactFriendList(testAuthUserId, testContactUserId);
                db.SaveChanges();
                fr = msService.IsFriend(testAuthUserId, testContactUserId);
            }

            //Assert
            Assert.True(fr);
        }
        public void GetAllFriendRelationship_ShouldReturnListOfFriend()
        {
            //Arrange
            List <FriendRelationship> friends = new List <FriendRelationship>();


            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);

                msService.AddContactFriendList(testAuthUserId, testContactUserId);
                db.SaveChanges();
                friends = msService.GetAllFriendRelationship(testAuthUserId).ToList();
            }

            //Assert
            Assert.NotEmpty(friends);
        }
Ejemplo n.º 9
0
        public void GetAllConversations_ShouldReturnListOfConversation()
        {
            //Arrange
            List <Conversation> conversations = null;

            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                msService.CreateConversation(testAuthUserId, testContactUserId, "*****@*****.**");
                db.SaveChanges();
            }

            //Act

            MessengerManager messengerManager = new MessengerManager();

            conversations = messengerManager.GetAllConversations(testAuthUserId).ToList();
            //Assert
            Assert.NotEmpty(conversations);
        }
Ejemplo n.º 10
0
        public void GetConversationFromId_ShouldReturnConversation()
        {
            //Arrange
            Conversation conversation = null;
            Conversation expected     = null;

            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                conversation = msService.CreateConversation(testAuthUserId, testContactUserId, "*****@*****.**");
                db.SaveChanges();
            }

            //Act
            MessengerManager messengerManager = new MessengerManager();

            expected = messengerManager.GetConversationFromId(conversation.Id);

            //Assert
            Assert.NotNull(expected);
        }
Ejemplo n.º 11
0
        public void DeleteConversation_FindDeletedConversationShouldReturnNull()
        {
            //Arrange
            Conversation conversation      = null;
            Conversation foundConversation = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                conversation = msService.CreateConversation(testAuthUserId, testContactUserId, "*****@*****.**");
                db.SaveChanges();

                MessengerManager messengerManager = new MessengerManager();
                conversation = messengerManager.DeleteConversation(conversation.Id);


                foundConversation = db.Conversations.Where(c => c.Id == conversation.Id).FirstOrDefault();
            }

            //Assert
            Assert.Null(foundConversation);
        }
        public void AddContactToFriendList_ShouldReturnFriendRelationship()
        {
            //Arrange
            FriendRelationship fr = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                if (msService.IsFriend(testAuthUserId, testContactUserId) == true)
                {
                    msService.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
                    db.SaveChanges();
                }

                fr = msService.AddContactFriendList(testAuthUserId, testContactUserId);

                db.SaveChanges();
            }

            //Assert
            Assert.NotNull(fr);
        }
        public void DeleteConversation_ShouldReturnAConversation()
        {
            //Arrange

            Conversation conversation      = null;
            Conversation foundConversation = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                conversation = msService.CreateConversation(testAuthUserId, testContactUserId, testContactUsername);
                db.SaveChanges();


                conversation = msService.DeleteConversation(conversation.Id);
                db.SaveChanges();

                foundConversation = db.Conversations.Where(c => c.Id == conversation.Id).FirstOrDefault();
            }

            //Assert
            Assert.Null(foundConversation);
        }
        public void RemoveContactFromFriendList_FindDeletedFriendShouldReturnNull()
        {
            //Arrange
            FriendRelationship DeletedFriend = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);

                if (msService.IsFriend(testAuthUserId, testContactUserId) == false)
                {
                    msService.AddContactFriendList(testAuthUserId, testContactUserId);
                    db.SaveChanges();
                }


                DeletedFriend = msService.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
                db.SaveChanges();
            }

            //Assert
            Assert.NotNull(DeletedFriend);
        }