示例#1
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");
        }
示例#2
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");
        }
示例#3
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");
        }
示例#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");
        }
示例#5
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");
        }
示例#6
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);
        }
        public IHttpActionResult UserLogin(UserEmailPassword userEmailPassword)
        {
            if (userEmailPassword == null ||
                userEmailPassword.Email == null ||
                userEmailPassword.Password == null ||
                userEmailPassword.Email == "" ||
                userEmailPassword.Password == "")
            {
                return(BadRequest("Insufficient input"));
            }

            UserDao userDao = userAuthentication.Login(userEmailPassword.Email, userEmailPassword.Password);

            if (userDao == null)
            {
                return(BadRequest("Incorrect credentials"));
            }

            UserDto user = new UserDto(userDao.Id, userDao.Email, userDao.FirstName,
                                       userDao.LastName, userDao.DateOfBirth, userDao.Gender,
                                       userDao.PhoneNumber, userDao.Address, userDao.PostCode,
                                       userDao.City, userDao.Country, userDao.MembershipId,
                                       userDao.Subscription, userDao.InterestedIn, userDao.RoleName);

            return(Ok(user));
        }
示例#8
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");
        }
示例#9
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");
            }
        }
示例#10
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");
        }
示例#11
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");
        }
示例#12
0
        public ActionResult Index()
        {
            userAuthentication.Login("*****@*****.**", "testTest*");

            ViewBag.Title = "Home Page";

            return(View());
        }
示例#13
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");
        }
示例#14
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");
        }
示例#15
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);
        }
示例#16
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");
        }
示例#17
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");
            }
        }
示例#18
0
 public IActionResult Index(LoginForm logForm)
 {
     if (ModelState.IsValid)
     {
         if (UserAuthentication.Login(logForm.Email, logForm.Password))
         {
             //HttpContext.Session.SetString("user", logInfo.Login);
             HttpContext.Session.SetString("Email", logForm.Email);
             return(RedirectToAction("Index", "Home"));
             //return RedirectToAction("Index", new RouteValueDictionary( new { controller = Home, action = "Index", auth = ea }));
         }
         else
         {
             ModelState.AddModelError("Email", logForm.Email);
             ModelState.AddModelError("Password", logForm.Password);
         }
     }
     return(View());
 }
示例#19
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");
        }
        public ActionResult Login(string returnUrl, LoginViewModel model)
        {
            SetLanguageFromUrl(returnUrl);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var success = UserAuthentication.Login(model.Username, model.Password, model.PersistLogin);

            if (success)
            {
                return(RedirectToUrlOrDefault(returnUrl));
            }

            ModelState.AddModelError(string.Empty, LocalizationService.GetString("/Account/LoginFailed"));

            return(View(model));
        }
示例#21
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");
        }
示例#22
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");
        }
示例#23
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");
        }
示例#24
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");
        }
示例#25
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");
        }
示例#26
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");
        }