Пример #1
0
        public void DeleteQuestionTest_Default()
        {
            QuestionTable.SaveQuestion(defaultQuestion);
            int res = QuestionTable.DeleteQuestion(defaultQuestion);

            Assert.AreEqual(res, 1);
        }
Пример #2
0
        public void GetQuestionIdTest_DoesNotExist()
        {
            QuestionTable.SaveQuestion(defaultQuestion);
            QuestionTable.DeleteQuestion(defaultQuestion);
            long res = QuestionTable.GetQuestionId(defaultQuestion);

            Assert.AreEqual(-1, res);
        }
Пример #3
0
        public void SaveQuestionTest_FreeTextType()
        {
            Question question = new Question("Free Type", new string[] { "A;B;C;D" });

            question.IsFreeText = true;
            int res = QuestionTable.SaveQuestion(question);

            QuestionTable.DeleteQuestion(question);
            Assert.AreEqual(res, 1);
        }
Пример #4
0
        public void TestQuestionInsert()
        {
            QuestionAnswer        qaTest       = new QuestionAnswer("Praha", true);
            QuestionAnswer        qaTest2      = new QuestionAnswer("Ostrava", false);
            List <QuestionAnswer> questionList = new List <QuestionAnswer>()
            {
                qaTest, qaTest2
            };

            Question generatedQuestion = QuestionTable.InsertQuestion(this.connection, 1, "Jaké je hlavní město ČR?", "closed", questionList);
            Question dbQuestion        = QuestionTable.GetQuestionById(this.connection, generatedQuestion.Id);

            Assert.AreEqual(generatedQuestion.Id, dbQuestion.Id);
            Assert.AreEqual(generatedQuestion.OwnerId, dbQuestion.OwnerId);
            Assert.AreEqual(generatedQuestion.Text, dbQuestion.Text);
            Assert.AreEqual(generatedQuestion.Type, dbQuestion.Type);

            Assert.AreEqual(questionList.Count, dbQuestion.Answers.Count);

            for (int i = 0; i < dbQuestion.Answers.Count; i++)
            {
                Assert.AreEqual(dbQuestion.Id, dbQuestion.Answers[i].QuestionId);
                Assert.AreEqual(i, dbQuestion.Answers[i].Index);
                Assert.AreEqual(questionList[i].Text, dbQuestion.Answers[i].Text);
                Assert.AreEqual(questionList[i].Correct, dbQuestion.Answers[i].Correct);
            }

            Assert.IsTrue(QuestionTable.DeleteQuestion(this.connection, dbQuestion));

            try
            {
                QuestionTable.GetQuestionById(this.connection, dbQuestion.Id);
                Assert.Fail("Otázka stále existuje");
            }
            catch (DatabaseException)
            {
            }
        }
Пример #5
0
        public void TestQuestionUpdate()
        {
            QuestionAnswer        qaTest       = new QuestionAnswer("Praha", true);
            QuestionAnswer        qaTest2      = new QuestionAnswer("Ostrava", false);
            List <QuestionAnswer> questionList = new List <QuestionAnswer>()
            {
                qaTest, qaTest2
            };

            Question generatedQuestion = QuestionTable.InsertQuestion(this.connection, 1, "Jaké je hlavní město ČR?", "closed", questionList);

            generatedQuestion.AddAnswer(new QuestionAnswer("Brno", false));
            generatedQuestion.Text = "Test";

            Assert.IsTrue(QuestionTable.UpdateQuestion(this.connection, generatedQuestion));

            Question updatedQuestion = QuestionTable.GetQuestionById(this.connection, generatedQuestion.Id);

            Assert.AreEqual("Test", updatedQuestion.Text);
            Assert.AreEqual(3, updatedQuestion.Answers.Count);
            Assert.AreEqual("Brno", updatedQuestion.Answers[2].Text);

            Assert.IsTrue(QuestionTable.DeleteQuestion(this.connection, generatedQuestion));
        }
Пример #6
0
 public void Cleanup()
 {
     QuestionTable.DeleteQuestion(defaultQuestion);
 }