Exemple #1
0
        public void DeleteTest()
        {
            // 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
            returnValue = returnTopic.Delete();

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

            // 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, "Data not deleted from the database");

            // extended check
            returnValue = returnTopic.Delete();
            Assert.IsFalse(returnValue, "\"Delete\" method returns true even for already deleted topic");
        }
Exemple #2
0
        public void TopicTest_TopicID()
        {
            // 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");
            int topicID = returnTopic.TopicID;

            // test method call
            returnTopic = new Topic(topicID);

            // initial 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");

            // extended check
            Assert.AreEqual(0, returnTopic.TotalQuestions,
                            "The number of total questions of the newly created topic is not 0");
        }
Exemple #3
0
        public void ViewIncorrectAnswerOptionTest()
        {
            // 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 extended check
            for (int i = 0; i < 4; i++)
            {
                string answerOption       = "Answer option " + (i + 1).ToString();
                string returnAnswerOption = question.ViewIncorrectAnswerOption(i);
                Assert.AreEqual(answerOption, returnAnswerOption,
                                "\"ViewIncorrectAnswerOption\" method returns invalid answer option");
            }
        }
Exemple #4
0
        public void ViewAllAnswerOptionsTest()
        {
            // 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
            List <string> list = question.ViewAllAnswerOptions();

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

            // extended check
            const string errorMessage = "\"ViewAllAnswerOptions\" method returns invalid answer option";

            for (int i = 0; i < 4; i++)
            {
                string answerOption = "Answer option " + (i + 1).ToString();
                Assert.AreEqual(answerOption, (list[i]), errorMessage);
            }
            Assert.AreEqual("Correct answer", list[4], errorMessage);
        }
Exemple #5
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");
        }
Exemple #6
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");
        }
Exemple #7
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");
        }
Exemple #8
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");
        }
Exemple #9
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");
        }
Exemple #10
0
        public void QuestionTest_QuestionID()
        {
            // 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);
            int questionID = question.QuestionID;

            // test method call
            question = new Q_Zone.Models.Question.Question(questionID);

            // 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 question string is not same as created");
            const string correctAnswer = "Correct answer";

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

            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);
        }
Exemple #11
0
        public void QuickMethodTest()
        {
            UserAuthentication.Login(TestData.UserData.Username, TestData.UserData.Password);

            Topic topic = TopicBank.AddTopic("sdfdsf");

            Q_Zone.Models.Question.Question q1 = QuestionBank.AddQuestion(topic);
            Q_Zone.Models.Question.Question q2 = QuestionBank.AddQuestion(topic);
            Q_Zone.Models.Question.Question q3 = QuestionBank.AddQuestion(topic);
            Q_Zone.Models.Question.Question q4 = QuestionBank.AddQuestion(topic);
            Q_Zone.Models.Question.Question q5 = QuestionBank.AddQuestion(topic);
            Q_Zone.Models.Question.Question q6 = QuestionBank.AddQuestion(topic);

            Quiz quiz = QuizBank.AddQuiz(topic);

            quiz.QuizName = "dfgfdgdf";
            quiz.AddQuestion(q1);
            quiz.AddQuestion(q2);
            quiz.AddQuestion(q3);
            quiz.AddQuestion(q4);
            quiz.AddQuestion(q5);
            quiz.AddQuestion(q6);
            quiz.DateTime = DateTime.UtcNow.AddMilliseconds(5);
            quiz.IsPublic = true;

            AnswerSheet answerSheet = new AnswerSheet(quiz);
            bool        testBool    = answerSheet.GiveAnswer(q1, "Correct answer");

            answerSheet.GiveAnswer(q2, "Answer option 1");
            answerSheet.GiveAnswer(q3, "Correct answer");
            answerSheet.GiveAnswer(q4, "Correct answer");
            answerSheet.Submit();
            string testString = answerSheet.ShowGivenAnswer(q2);

            Result r1 = new Result(quiz);
            Result r2 = new Result(1, quiz);

            testBool = (r1 == r2);

            List <Quiz>   quizList = RankList.ViewParticipatedQuizzes(maximumDuration: 5000);
            List <Result> rankList = RankList.ViewRankList(quiz);

            quizList = RankList.ViewStartedQuizzes(searchName: "d");
        }
Exemple #12
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");
            }
        }
Exemple #13
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");
        }
Exemple #14
0
        public void DeleteTest()
        {
            // 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);
            int questionID = question.QuestionID;

            // test method call
            returnValue = question.Delete();

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

            // initial database check
            DataTable dataTable = DataAccessLayer.SelectCommand(DataAccessLayer.SelectCommandString(
                                                                    Q_Zone.Models.Question.Question.QuestionTableID,
                                                                    Q_Zone.Models.Question.Question.QuestionTable,
                                                                    Q_Zone.Models.Question.Question.QuestionTableID + " = :questionID"),
                                                                new CommandParameter(":questionID", questionID));

            Assert.AreEqual(0, dataTable.Rows.Count, "Data not deleted from the database");

            // extended check
            returnValue = question.Delete();
            Assert.IsFalse(returnValue, "\"Delete\" method returns true even for already deleted question");
        }
Exemple #15
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");
        }
Exemple #16
0
        public void TotalQuestionsTest()
        {
            // 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");
            for (int i = 0; i < 5; i++)
            {
                QuestionBank.AddQuestion(returnTopic);
            }

            // test method call
            int totalQuestions = returnTopic.TotalQuestions;

            // initial check
            Assert.AreEqual(5, totalQuestions, "The number of total questions of the topic is not correct");

            // extended check
            List <Q_Zone.Models.Question.Question> list = returnTopic.ViewQuestions();

            foreach (Q_Zone.Models.Question.Question questionObject in list)
            {
                questionObject.Delete();
            }
            totalQuestions = returnTopic.TotalQuestions;
            Assert.AreEqual(0, totalQuestions, "The number of total questions of the topic is not correct");
        }
Exemple #17
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");
        }
Exemple #18
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");
        }