/// <summary>
        /// Returns a question list of the given page range that can be answered
        /// </summary>
        public QuestionData GetAnswerableQuestionListInPageRange(int surveyId, int startPageNumber, int endPageNumber)
        {
            QuestionData questions = QuestionFactory.Create().GetAnswerableQuestionListInPageRange(surveyId, startPageNumber, endPageNumber);

            this.ParseHTMLTagsFromQuestionText(questions, 80);
            return(questions);
        }
Exemple #2
0
        public void QuizRepository_CreateWithChoices_HasChoices()
        {
            const string quizName = "Quiz name";

            var question1 = QuestionFactory.Create("Some question",
                                                   ChoiceFactory.Create("Some choice", 10),
                                                   ChoiceFactory.Create("Some other choice", 0),
                                                   ChoiceFactory.Create("Some third choice", 20)
                                                   );
            var question2 = QuestionFactory.Create("Some other question",
                                                   ChoiceFactory.Create("Some choice", 10),
                                                   ChoiceFactory.Create("Some other choice", 0)
                                                   );

            var repo = QuizRepository.Instance;
            var quiz = repo.CreateQuiz(quizName, question1, question2);

            Assert.That(quiz.Questions.Count, Is.EqualTo(2));
            Assert.That(quiz.Questions[0].QuestionString, Is.EqualTo("Some question"));
            Assert.That(quiz.Questions[0].Choices.Count, Is.EqualTo(3));
            Assert.That(quiz.Questions[0].Choices[1].ChoiceText, Is.EqualTo("Some other choice"));
            Assert.That(quiz.Questions[0].Choices[2].Value, Is.EqualTo(20));
            Assert.That(quiz.Questions[1].QuestionString, Is.EqualTo("Some other question"));
            Assert.That(quiz.Questions[1].Choices.Count, Is.EqualTo(2));
            Assert.That(quiz.Questions[1].Choices[0].ChoiceText, Is.EqualTo("Some choice"));
            Assert.That(quiz.Questions[1].Choices[1].Value, Is.EqualTo(0));
        }
        /// <summary>
        /// Returns a question list that can be answered and that don't have any questions
        /// </summary>
        /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
        /// <returns>A question object collection</returns>
        public QuestionData GetAnswerableSingleQuestionListWithoutChilds(int surveyId)
        {
            QuestionData answerableSingleQuestionListWithoutChilds = QuestionFactory.Create().GetAnswerableSingleQuestionListWithoutChilds(surveyId);

            this.ParseHTMLTagsFromQuestionText(answerableSingleQuestionListWithoutChilds, 80);
            return(answerableSingleQuestionListWithoutChilds);
        }
        /// <summary>
        /// Returns the question and its answers results
        /// </summary>
        public QuestionResultsData GetQuestionResults(int questionId, int filterId, string sortOrder, string languageCode, DateTime startDate, DateTime endDate)
        {
            QuestionResultsData data = QuestionFactory.Create().GetQuestionResults(questionId, filterId, sortOrder, languageCode, startDate, endDate);

            if (data.Questions.Rows.Count == 0)
            {
                throw new QuestionNotFoundException();
            }
            foreach (QuestionResultsData.QuestionsRow row in data.Questions)
            {
                if (row.QuestionText != null)
                {
                    row.QuestionText = Regex.Replace(row.QuestionText, "<[^>]*>", " ");
                    if (row.QuestionText.Length > 40)
                    {
                        row.QuestionText = row.QuestionText.Substring(0, 40) + "...";
                    }
                }
                if (row.ParentQuestionText != null)
                {
                    row.ParentQuestionText = Regex.Replace(row.ParentQuestionText, "<[^>]*>", " ");
                    if (row.ParentQuestionText.Length > 40)
                    {
                        row.ParentQuestionText = row.ParentQuestionText.Substring(0, 40) + "...";
                    }
                }
            }
            return(data);
        }
        /// <summary>
        /// Returns a question list of the given page that can be answered
        /// </summary>
        /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
        /// <returns>A question object collection</returns>
        public QuestionData GetAnswerableQuestionList(int surveyId, int pageNumber)
        {
            QuestionData answerableQuestionList = QuestionFactory.Create().GetAnswerableQuestionList(surveyId, pageNumber);

            this.ParseHTMLTagsFromQuestionText(answerableQuestionList, 80);
            return(answerableQuestionList);
        }
        /// <summary>
        /// Returns a question list of the given page with only text, questionid and display order field
        /// from the given survey that have at leat one selectable answer type
        /// </summary>
        /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
        /// <returns>A question object collection</returns>
        public QuestionData GetQuestionListWithSelectableAnswers(int surveyId, int pageNumber)
        {
            QuestionData questionListWithSelectableAnswers = QuestionFactory.Create().GetQuestionListWithSelectableAnswers(surveyId, pageNumber);

            this.ParseHTMLTagsFromQuestionText(questionListWithSelectableAnswers, 80);
            return(questionListWithSelectableAnswers);
        }
        /// <summary>
        /// Returns all question listed in the library without their child questions
        /// </summary>
        public QuestionData GetLibraryQuestionListWithoutChilds(int libraryId)
        {
            QuestionData libraryQuestionListWithoutChilds = QuestionFactory.Create().GetLibraryQuestionListWithoutChilds(libraryId);

            this.ParseHTMLTagsFromQuestionText(libraryQuestionListWithoutChilds, 80);
            return(libraryQuestionListWithoutChilds);
        }
        /// <summary>
        /// Import the given questions into the DB
        /// </summary>
        public void ImportQuestions(NSurveyQuestion importQuestions, int userId)
        {
            IQuestion question = QuestionFactory.Create();

            this.TurnOverPrimaryKeys(importQuestions);
            question.ImportQuestions(importQuestions, userId);
        }
 private static void FillQuizzes(QuizRepository quizzes)
 {
     quizzes.CreateQuiz
     (
         "Test quiz",
         QuestionFactory.Create("Some question 1?",
                                ChoiceFactory.Create("Meh 1", 0),
                                ChoiceFactory.Create("Kinda 1", 5),
                                ChoiceFactory.Create("Yes 1!", 10)),
         QuestionFactory.Create("Some question 2?",
                                ChoiceFactory.Create("Meh 2", 0),
                                ChoiceFactory.Create("Kinda 2", 5),
                                ChoiceFactory.Create("Yes 2!", 10)),
         QuestionFactory.Create("Some question 3?",
                                ChoiceFactory.Create("Meh 3", 0),
                                ChoiceFactory.Create("Kinda 3", 5),
                                ChoiceFactory.Create("Yes 3!", 10))
     );
     quizzes.CreateQuiz
     (
         "Test quiz 2",
         QuestionFactory.Create("Some question 1?",
                                ChoiceFactory.Create("Meh 1", 0),
                                ChoiceFactory.Create("Kinda 1", 5),
                                ChoiceFactory.Create("Yes 1!", 10)),
         QuestionFactory.Create("Some question 2?",
                                ChoiceFactory.Create("Meh 2", 0),
                                ChoiceFactory.Create("Kinda 2", 5),
                                ChoiceFactory.Create("Yes 2!", 10)),
         QuestionFactory.Create("Some question 3?",
                                ChoiceFactory.Create("Meh 3", 0),
                                ChoiceFactory.Create("Kinda 3", 5),
                                ChoiceFactory.Create("Yes 3!", 10))
     );
 }
        /// <summary>
        /// Returns all question listed in the library
        /// </summary>
        public QuestionData GetLibraryQuestionList(int libraryId)
        {
            QuestionData libraryQuestionList = QuestionFactory.Create().GetLibraryQuestionList(libraryId);

            this.ParseHTMLTagsFromQuestionText(libraryQuestionList, 80);
            return(libraryQuestionList);
        }
        public void Create_WithFT_WillCreateAFreeTextQuestion()
        {
            var questionFactory = new QuestionFactory();

            var question = questionFactory.Create(new StringReader("Q1 FT Name"));

            Assert.IsInstanceOf(typeof(FreeTextQuestion), question);
        }
Exemple #12
0
        public void CreateQuestion_Always_WillCreateAFreeTextQuestion()
        {
            var questionFactory = new QuestionFactory();

            Base question = questionFactory.Create(new StringReader("Q1 Name"));

            Assert.IsInstanceOf(typeof(FreeTextQuestion), question);
        }
        public void Create_WhenFT_WillReturnAFreeTextQuestion()
        {
            var questionFactory = new QuestionFactory();

            Base question = questionFactory.Create(new StringReader("FT Name"));

            Assert.IsInstanceOf(typeof(FreeTextQuestion), question);
        }
        public void Create_WithSC_WillCreateASingleChoiceQuestion()
        {
            var questionFactory = new QuestionFactory();

            Base question = questionFactory.Create(new StringReader("SC Sex 2 Female Male"));

            Assert.IsInstanceOf(typeof(SingleChoiceQuestion), question);
        }
        public void Create_WhenQuestionOfTypeFT_WillReturnFreeText()
        {
            var questionFactory = new QuestionFactory();

            var freeTextQuestion = questionFactory.Create(new StringReader("FT Numele"));

            Assert.That(freeTextQuestion.Name, Is.EqualTo("Numele"));
        }
        public void Create_WithMC_WillCallCreateonAMultipleChoiceQuestion()
        {
            var mockMultipleChoiceQuestionFactory = new Mock <MultipleChoiceQuestionFactory>();
            var questionFactory = new QuestionFactory {
                MultipleChoiceQuestion = mockMultipleChoiceQuestionFactory.Object
            };

            Base question = questionFactory.Create(new StringReader("MC Optiuni 3 op1 op2 op3"));
        }
        public void TestDesafio6()
        {
            QuestionFactory <IQuestion> .Register(6, () => new SixthQuestion("SKY"));

            IQuestion question = QuestionFactory <IQuestion> .Create(6);

            var result = question.Execute();

            Assert.AreEqual(10, result.ListResultsInt[0], "Válido");
        }
        public void TestDesafio3()
        {
            QuestionFactory <IQuestion> .Register(3, () => new ThirdQuestion());

            IQuestion question = QuestionFactory <IQuestion> .Create(3);

            var result = question.Execute();

            Assert.AreEqual(10946, result.ListResultsInt[0], "Válido");
        }
        public void TestDesafio2()
        {
            QuestionFactory <IQuestion> .Register(2, () => new SecondQuestion(new int[] { 1, 2, 3, 4, 5 }));

            IQuestion question = QuestionFactory <IQuestion> .Create(2);

            var result = question.Execute();

            Assert.AreEqual(55, result.ListResultsInt[0], "Válido");
        }
        /// <summary>
        /// Return a question object that reflects the database question
        /// </summary>
        /// <param name="questionId">Id of the question you need</param>
        /// <returns>A questiondata object with the current database values</returns>
        public QuestionData GetQuestionById(int questionId, string languageCode)
        {
            QuestionData questionById = QuestionFactory.Create().GetQuestionById(questionId, languageCode);

            if (questionById.Questions.Rows.Count == 0)
            {
                throw new QuestionNotFoundException();
            }
            return(questionById);
        }
        public void Create_WithSC_WillSetTheListOfPossibleAnswers()
        {
            var mockQuestion    = new Mock <IQuestionFactory>();
            var questionFactory = new QuestionFactory {
                AnswersFactory = mockQuestion.Object
            };

            Base question = questionFactory.Create(new StringReader("Q1 SC Sex 2 Female Male"));

            Assert.AreEqual(2, question.Items.Count);
        }
        public void Create_WithSC_WillCreateASingleChoiceQuestion()
        {
            var mockChoiceQuestion = new Mock <IChoiceQuestionFactory>();
            var questionFactory    = new QuestionFactory {
                SingleChoiceQuestion = mockChoiceQuestion.Object
            };

            Question question = questionFactory.Create(new StringReader("SC Sex 2 Female Male"));

            mockChoiceQuestion.Verify(m => m.Create("SC Sex 2 Female Male"), Times.Once());
        }
        public void TestDesafio1()
        {
            QuestionFactory <IQuestion> .Register(1, () => new FirstQuestion("Renan", "Tavares"));

            IQuestion question = QuestionFactory <IQuestion> .Create(1);

            var result = question.Execute();
            var count  = result.ListOfResults.Count;

            Assert.AreEqual(100, count, "Válido");
        }
        public void Create_WhenMC_WillCallCreateChoiceQuestion()
        {
            var mockMultipleChoiceQuestionFactory = new Mock <IChoiceQuestionFactory>();
            var questionFactory = new QuestionFactory {
                MultipleChoiceQuestionFactory = mockMultipleChoiceQuestionFactory.Object
            };

            Base question = questionFactory.Create(new StringReader("MC Optiuni 3 op1 op2 op3"));

            mockMultipleChoiceQuestionFactory.Verify(m => m.CreateChoiceQuestion(It.IsAny <string>()), Times.Once());
        }
Exemple #25
0
        public void Create_WithMC_WillCallCreateOnMultipleChoiceQuestion()
        {
            var mockMultipleChoiceQuestion = new Mock <IChoiceQuestionFactory>();
            var questionFactory            = new QuestionFactory {
                MultipleChoiceQuestion = mockMultipleChoiceQuestion.Object
            };

            questionFactory.Create(new StringReader("MC Optiuni 3 op1 op2 op3"));

            mockMultipleChoiceQuestion.Verify(m => m.Create(It.IsAny <string>()));
        }
        public void Create_WhenSC_WillCallCreateChoiceQuestion()
        {
            var mockSingleChoiceQuestionFactory = new Mock <IChoiceQuestionFactory>();
            var questionFactory = new QuestionFactory {
                SingleChoiceQuestionFactory = mockSingleChoiceQuestionFactory.Object
            };

            Base question = questionFactory.Create(new StringReader("SC Sex 2 Female Male"));

            mockSingleChoiceQuestionFactory.Verify(m => m.CreateChoiceQuestion(It.IsAny <string>()), Times.Once());
        }
        /// <summary>
        /// Returns all question details, answers and answer types
        /// </summary>
        public NSurveyQuestion GetQuestionForExport(int questionId)
        {
            NSurveyQuestion questionForExport = QuestionFactory.Create().GetQuestionForExport(questionId);
            int             num = 1;

            foreach (NSurveyQuestion.QuestionRow row in questionForExport.Question)
            {
                row.QuestionId = num;
                num++;
            }
            return(questionForExport);
        }
        public void TestDesafio4()
        {
            QuestionFactory <IQuestion> .Register(4, () => new FourthQuestion(TreeDomain.GenerateTree(), 9));

            IQuestion question = QuestionFactory <IQuestion> .Create(4);

            var result = question.Execute();

            int[] actual = result.ListResultsInt.ToArray();
            Array.Reverse(actual);
            CollectionAssert.AreEqual(new int[] { 1, 4, 2, 12, 13, 9 }, actual);
        }
Exemple #29
0
        public void Create_WithSC_WillReturnASingleChoiceQuestion()
        {
            var mockSingleChoiceQFactory = new Mock <IChoiceQuestionFactory>();
            var questionFactory          = new QuestionFactory {
                SingleChoiceQuestion = mockSingleChoiceQFactory.Object
            };

            Base question = questionFactory.Create(new StringReader("Q1 SC Sex 2 Female Male"));

            Assert.IsInstanceOf(typeof(SingleChoiceQuestion), question);
            Assert.AreEqual(2, question.Items.Count);
        }
        public ActionResult Challenge()
        {
            ViewBag.Message = "Desafio 4.";
            QuestionFactory <IQuestion> .Register(4, () => new FourthQuestion(TreeDomain.GenerateTree(), 9));

            IQuestion question = QuestionFactory <IQuestion> .Create(4);

            var result = question.Execute();
            var model  = new DesafioModel();

            model.Resultado = result.ListResultsInt.ToArray();
            return(View(model));
        }