Beispiel #1
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");
        }