Esempio n. 1
0
        public void DifficultyTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            Q_Zone.Models.Question.Question question = new Q_Zone.Models.Question.Question(returnTopic);

            // test method call
            Assert.AreEqual(Difficulty.None, question.DifficultyLevel,
                            "Question's difficulty level is not same as created");
            const Difficulty newDifficulty = Difficulty.Hard;

            question.DifficultyLevel = newDifficulty;

            // initial check
            Assert.AreEqual(newDifficulty, question.DifficultyLevel,
                            "Question's difficulty level does not change even after login");

            // security check
            UserAuthentication.Logout();
            question.DifficultyLevel = Difficulty.Medium;
            Assert.AreEqual(newDifficulty, question.DifficultyLevel,
                            "Question's difficulty level changes even after logout");
        }
Esempio n. 2
0
        public void LoginTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.SignUp(UserData.Username, UserData.Password, UserData.Email);

            Assert.IsTrue(returnValue, "\"SignUp\" method returns false");

            // prerequisite check
            Assert.IsTrue(returnValue, "\"SignUp\" method returns false");

            // test method call
            returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // initial check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");

            // extended check
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");
            Assert.AreEqual(UserData.Username, user.Username,
                            "\"LoggedInUser\" is different from the actual logged-in user");

            // security check
            UserAuthentication.Logout();
            returnValue = UserAuthentication.Login(UserData.Username, "a wrong password");
            Assert.IsFalse(returnValue, "\"Login\" method returns true even for wrong password");
            returnValue = UserAuthentication.Login("wrong username", UserData.Password);
            Assert.IsFalse(returnValue, "\"Login\" method returns true even for wrong username");
        }
Esempio n. 3
0
        public void ChangePasswordTest()
        {
            // dummy new password for test
            const string newPassword = "******";

            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initial check
            const string errorMessage = "Password not changed even for correct current password";

            returnValue = user.ChangePassword(UserData.Password, newPassword);
            Assert.IsTrue(returnValue, errorMessage);

            // extended check
            returnValue = user.ChangePassword(newPassword, UserData.Password);
            Assert.IsTrue(returnValue, errorMessage);
            returnValue = user.ChangePassword("this_is_a_wrong_password", newPassword);
            Assert.IsFalse(returnValue, "Password changed even for wrong current password");

            // security check
            UserAuthentication.Logout();
            returnValue = user.ChangePassword(UserData.Password, newPassword);
            Assert.IsFalse(returnValue, "Password changed even after logout");
        }
Esempio n. 4
0
        public void CorrectAnswerTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            Q_Zone.Models.Question.Question question = new Q_Zone.Models.Question.Question(returnTopic);

            // test method call
            Assert.AreEqual("Correct answer", question.CorrectAnswer,
                            "Question's correct answer is not same as created");
            const string newCorrectAnswer = "This is a new correct answer";

            question.CorrectAnswer = newCorrectAnswer;

            // initial check
            Assert.AreEqual(newCorrectAnswer, question.CorrectAnswer,
                            "Question's correct answer does not change even after login");

            // security check
            UserAuthentication.Logout();
            question.CorrectAnswer = QuestionData.CorrectAnswer;
            Assert.AreEqual(newCorrectAnswer, question.CorrectAnswer,
                            "Question's correct answer changes even after logout");
        }
Esempio n. 5
0
        public void NameTest()
        {
            // dummy new email for test
            const string newName = "Abc_new name";

            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initial check
            const string errorMessage = "Name not changed";

            user.Name = newName;
            Assert.AreEqual(newName, user.Name, errorMessage);

            // extended check
            user.Name = UserData.Name;
            Assert.AreEqual(UserData.Name, user.Name, errorMessage);

            // security check
            UserAuthentication.Logout();
            user.Name = newName;
            Assert.AreNotEqual(newName, user.Name, "Name changed even after logout");
        }
Esempio n. 6
0
        public void AddQuestionTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");

            // test method call
            Q_Zone.Models.Question.Question question = QuestionBank.AddQuestion(returnTopic);

            // initial check
            Assert.IsNotNull(question, "\"AddQuestion\" method returns null");

            // extended check
            Assert.AreEqual(UserAuthentication.LoggedInUser, question.Owner, "Question owner is not same as created");
            Assert.AreEqual(QuestionData.TopicName, question.Topic.TopicName, "Question's topic is not same as created");

            // security check
            UserAuthentication.Logout();
            question = QuestionBank.AddQuestion(returnTopic);
            Assert.IsNull(question, "\"AddQuestion\" method does not return null even after logout");
        }
Esempio n. 7
0
        public void ViewTopicsTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            foreach (string topicName in QuestionData.TopicNames)
            {
                TopicBank.AddTopic(topicName);
            }

            // test method call
            List <Topic> list = TopicBank.ViewTopics();

            // initial check
            Assert.AreEqual(5, list.Count, "\"ViewTopics\" method does not return all topics");

            // initial database check
            List <string> topicNameList = TestHelper.GetTopicNameListFromTopicList(list);
            const string  errorMessage  = "Topic not shown in the list";

            Assert.IsTrue(topicNameList.Contains(QuestionData.TopicName), errorMessage);
            foreach (string topicName in QuestionData.TopicNames)
            {
                Assert.IsTrue(topicNameList.Contains(topicName), errorMessage);
            }

            // extended check
            list = TopicBank.ViewTopics("DuMmY");
            Assert.AreEqual(2, list.Count, "\"ViewTopics\" method does not return all specified topics");
            for (int i = 0; i < 2; i++)
            {
                Assert.IsTrue(topicNameList.Contains(QuestionData.TopicNames[0]), errorMessage);
            }
            list = TopicBank.ViewTopics("never_found");
            Assert.AreEqual(0, list.Count, "\"ViewTopics\" method returns invalid topics");

            // security check
            UserAuthentication.Logout();
            list = TopicBank.ViewTopics();
            Assert.IsNull(list, "Topics shown even after logout");
        }
Esempio n. 8
0
        public void TopicNameTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            Topic returnTopic0 = TopicBank.AddTopic(QuestionData.TopicNames[0]);

            // test method call
            returnTopic.TopicName = QuestionData.TopicNames[1];

            // initial check
            Assert.AreEqual(QuestionData.TopicNames[1], returnTopic.TopicName,
                            "Topic's topic name does not change even after login");

            // initial database check
            DataTable dataTable = DataAccessLayer.SelectCommand(DataAccessLayer.SelectCommandString(
                                                                    Topic.TopicTableID, Topic.TopicTable, "Owner_ID = :ownerID AND Topic_Name = :topicName"),
                                                                new CommandParameter(":ownerID", _userID), new CommandParameter(":topicName", QuestionData.TopicName));

            Assert.AreEqual(0, dataTable.Rows.Count, "Topic name not changed in the database");

            // extended check
            returnTopic0.TopicName = QuestionData.TopicNames[1];
            Assert.AreEqual(QuestionData.TopicNames[0], returnTopic0.TopicName,
                            "Topic name changed even for duplicate name");
            returnTopic0.TopicName = QuestionData.TopicName;
            const string errorMessage = "Topic name not changed even for unique name";

            Assert.AreEqual(QuestionData.TopicName, returnTopic0.TopicName, errorMessage);
            returnTopic.TopicName = QuestionData.TopicNames[0];
            Assert.AreEqual(QuestionData.TopicNames[0], returnTopic.TopicName, errorMessage);

            // security check
            UserAuthentication.Logout();
            returnTopic.TopicName = QuestionData.TopicNames[1];
            Assert.AreEqual(QuestionData.TopicNames[0], returnTopic.TopicName, "Topic name changed even after logout");
        }
Esempio n. 9
0
        public void EditIncorrectOptionTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            Q_Zone.Models.Question.Question question = new Q_Zone.Models.Question.Question(returnTopic);

            // test method call and initial check
            for (int i = 0; i < 4; i++)
            {
                returnValue = question.EditIncorrectOption(i, QuestionData.AnswerOptions[i]);
                Assert.IsTrue(returnValue, "\"EditIncorrectOption\" method returns false");
            }

            // extended check
            List <string> list = question.ViewAllAnswerOptions();

            foreach (string answerOption in list)
            {
                returnValue = list.Contains(answerOption);
                Assert.IsTrue(returnValue, "Question's incorrect answer option not changed");
            }

            // security check
            UserAuthentication.Logout();
            returnValue = question.EditIncorrectOption(2, "changed answer option");
            Assert.IsFalse(returnValue, "Question's incorrect answer option changed even after logout");
            list = question.ViewAllAnswerOptions();
            foreach (string answerOption in list)
            {
                returnValue = list.Contains(answerOption);
                Assert.IsTrue(returnValue, "Question's incorrect answer option not changed");
            }
        }
Esempio n. 10
0
        public void ViewQuestionsTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            Q_Zone.Models.Question.Question question = QuestionBank.AddQuestion(returnTopic);
            question.QuestionString = QuestionData.QuestionString;
            foreach (string questionString in QuestionData.QuestionStrings)
            {
                question = QuestionBank.AddQuestion(returnTopic);
                question.QuestionString = questionString;
            }

            // test method call
            List <Q_Zone.Models.Question.Question> list = returnTopic.ViewQuestions();

            // initial check
            Assert.AreEqual(5, list.Count, "\"ViewQuestions\" method does not return all questions");

            // initial database check
            List <string> questionStringList = TestHelper.GetQuestionStringListFromQuestionList(list);

            Assert.IsTrue(questionStringList.Contains(QuestionData.QuestionString), "Question not shown in the list");
            foreach (string questionString in QuestionData.QuestionStrings)
            {
                Assert.IsTrue(questionStringList.Contains(questionString), "Question not shown in the list");
            }

            // security check
            UserAuthentication.Logout();
            list = QuestionBank.ViewQuestions();
            Assert.IsNull(list, "Questions shown even after logout");
        }
Esempio n. 11
0
        public void TopicTest_TopicName()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // test method call and initial check
            Topic returnTopic = null;

            try {
                returnTopic = new Topic(QuestionData.TopicName);
            }
            catch (Exception exception) {
                Debug.WriteLine(exception.Message);
                Assert.Fail("\"Topic(topicName)\" constructor throws exception");
            }

            // extended check
            Assert.AreEqual(UserAuthentication.LoggedInUser, returnTopic.Owner, "Topic's owner is not same as created");
            Assert.AreEqual(QuestionData.TopicName, returnTopic.TopicName, "Topic's topic name is not same as created");
            Assert.AreEqual(0, returnTopic.TotalQuestions,
                            "The number of total questions of the newly created topic is not 0");

            // security check
            UserAuthentication.Logout();
            returnTopic = null;
            try {
                returnTopic = new Topic(QuestionData.TopicNames[0]);
            }
            catch (InvalidCredentialException exception) {
                Debug.WriteLine(exception.Message);
            }
            Assert.IsNull(returnTopic, "\"Topic(topicName)\" constructor does not throw exception even after logout");
        }
Esempio n. 12
0
        public void AddTopicTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // test method call
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            // initial check
            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");

            // initial database check
            DataTable dataTable = DataAccessLayer.SelectCommand(DataAccessLayer.SelectCommandString(
                                                                    "Topic_Name", Topic.TopicTable, "Owner_ID = :ownerID"),
                                                                new CommandParameter(":ownerID", _userID));

            Assert.AreEqual(1, dataTable.Rows.Count, "Data not added to the database");
            Assert.AreEqual(QuestionData.TopicName, ((string)(dataTable.Rows[0][0])), "Topic name does not match");

            // extended check
            returnTopic = TopicBank.AddTopic(QuestionData.TopicName);
            Assert.IsNull(returnTopic, "Topic added even for duplicate name");
            returnTopic = TopicBank.AddTopic(QuestionData.TopicNames[0]);
            Assert.IsNotNull(returnTopic, "Topic not added even for different name");

            // security check
            UserAuthentication.Logout();
            returnTopic = TopicBank.AddTopic(QuestionData.TopicNames[1]);
            Assert.IsNull(returnTopic, "Topic added even after logout");
        }
Esempio n. 13
0
        public void QuestionTest_Topic()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");

            // test method call
            Q_Zone.Models.Question.Question question = null;
            try {
                question = new Q_Zone.Models.Question.Question(returnTopic);
            }
            catch (Exception exception) {
                Debug.WriteLine(exception.Message);
                Assert.Fail("\"Question(topic)\" constructor throws exception");
            }

            // initial check
            Assert.AreEqual(UserAuthentication.LoggedInUser, question.Owner, "Question's owner is not same as created");
            Assert.AreEqual(QuestionData.TopicName, question.Topic.TopicName, "Question's topic is not same as created");

            // extended check
            Assert.AreEqual("Question string", question.QuestionString,
                            "Question's default question string is not same as intended");
            const string correctAnswer = "Correct answer";

            Assert.AreEqual(correctAnswer,
                            question.CorrectAnswer, "Question's default correct answer is not same as intended");
            Assert.AreEqual(Difficulty.None,
                            question.DifficultyLevel, "Question's default difficulty level is not same as intended");
            List <string> list         = question.ViewAllAnswerOptions();
            const string  errorMessage = "Question's answer option list is not same as intended";

            Assert.AreEqual(5, list.Count, errorMessage);
            for (int i = 0; i < 4; i++)
            {
                string answerOption = "Answer option " + (i + 1).ToString();
                Assert.AreEqual(answerOption, (list[i]), errorMessage);
            }
            Assert.AreEqual(correctAnswer, (list[4]), errorMessage);

            // security check
            UserAuthentication.Logout();
            question = null;
            try {
                question = new Q_Zone.Models.Question.Question(returnTopic);
            }
            catch (InvalidCredentialException exception) {
                Debug.WriteLine(exception.Message);
            }
            Assert.IsNull(question, "\"Question(topic)\" constructor does not throw exception even after logout");
        }
 public ActionResult Logout(string returnUrl)
 {
     UserAuthentication.Logout();
     return(RedirectToUrlOrDefault(returnUrl));
 }
Esempio n. 15
0
        public void ViewQuestionsTest()
        {
            // prerequisite method call
            bool returnValue = UserAuthentication.Login(UserData.Username, UserData.Password);

            // prerequisite check
            Assert.IsTrue(returnValue, "\"Login\" method returns false");
            User user = UserAuthentication.LoggedInUser;

            Assert.IsNotNull(user, "\"LoggedInUser\" is null");

            // initialization
            Topic returnTopic = TopicBank.AddTopic(QuestionData.TopicName);

            Assert.IsNotNull(returnTopic, "\"AddTopic\" method returns null");
            Topic returnTopic0 = TopicBank.AddTopic(QuestionData.TopicNames[0]);

            Q_Zone.Models.Question.Question question = QuestionBank.AddQuestion(returnTopic);
            Assert.IsNotNull(question, "\"AddQuestion\" method returns null");
            question.QuestionString  = QuestionData.QuestionString;
            question.DifficultyLevel = Difficulty.Hard;
            for (int i = 0; i < 3; i++)
            {
                question = QuestionBank.AddQuestion(returnTopic);
                question.QuestionString  = QuestionData.QuestionStrings[i];
                question.DifficultyLevel = Difficulty.Easy;
            }
            question = QuestionBank.AddQuestion(returnTopic0);
            question.QuestionString  = QuestionData.QuestionStrings[3];
            question.DifficultyLevel = Difficulty.Medium;

            // test method call
            List <Q_Zone.Models.Question.Question> list = QuestionBank.ViewQuestions();

            // initial check
            Assert.AreEqual(5, list.Count, "\"ViewQuestions\" method does not return all questions");

            // initial database check
            List <string> questionStringList = TestHelper.GetQuestionStringListFromQuestionList(list);

            Assert.IsTrue(questionStringList.Contains(QuestionData.QuestionString), "Question not shown in the list");
            foreach (string questionString in QuestionData.QuestionStrings)
            {
                Assert.IsTrue(questionStringList.Contains(questionString), "Question not shown in the list");
            }

            // extended check
            const string errorMessage = "\"ViewQuestions\" method does not return all specified questions";

            list = QuestionBank.ViewQuestions(QuestionData.TopicName);
            Assert.AreEqual(4, list.Count, errorMessage);
            questionStringList = TestHelper.GetQuestionStringListFromQuestionList(list);
            Assert.IsTrue(questionStringList.Contains(QuestionData.QuestionString), errorMessage);
            for (int i = 0; i < 3; i++)
            {
                Assert.IsTrue(questionStringList.Contains(QuestionData.QuestionStrings[i]), errorMessage);
            }
            list = QuestionBank.ViewQuestions(QuestionData.TopicName, "Dummy");
            Assert.AreEqual(3, list.Count, errorMessage);
            list = QuestionBank.ViewQuestions(QuestionData.TopicName, "Dummy", Difficulty.Easy);
            Assert.AreEqual(2, list.Count, errorMessage);
            list = QuestionBank.ViewQuestions(phrase: "Dummy");
            Assert.AreEqual(4, list.Count, errorMessage);
            list = QuestionBank.ViewQuestions(difficulty: Difficulty.Medium);
            Assert.AreEqual(1, list.Count, errorMessage);
            list = QuestionBank.ViewQuestions(QuestionData.TopicName, "", Difficulty.Easy);
            Assert.AreEqual(3, list.Count, errorMessage);
            list = QuestionBank.ViewQuestions("", "dummY", Difficulty.Hard);
            Assert.AreEqual(1, list.Count, errorMessage);

            // security check
            UserAuthentication.Logout();
            list = QuestionBank.ViewQuestions();
            Assert.IsNull(list, "Questions shown even after logout");
        }