예제 #1
0
        public void ValidateAnswers_FailsWhenAnswersNotForQuiz()
        {
            var quizManager = new QuizManager();

            var quiz = new MemberTrack.Data.Entities.Quizzes.Quiz {
                Id = 1,
            };
            var quiz2 = new MemberTrack.Data.Entities.Quizzes.Quiz {
                Id = 2,
            };

            var question = new Question {
                Id = 10, QuizId = quiz.Id, Quiz = quiz
            };
            var question2 = new Question {
                Id = 11, QuizId = quiz.Id, Quiz = quiz
            };

            var allAnswers = new List <Answer>
            {
                new Answer
                {
                    Id         = 100,
                    QuestionId = question.Id,
                    Question   = question
                },
                new Answer
                {
                    Id         = 101,
                    QuestionId = question2.Id,
                    Question   = question2
                },
                new Answer
                {
                    Id         = 102,
                    QuestionId = question.Id,
                    Question   = question
                },
            };

            var answerIds = new List <long> {
                100, 102
            };

            quizManager.ValidateAnswers(quiz2, allAnswers, answerIds);
        }
예제 #2
0
        public void ValidateAnswers_FailsWhenAnswersNotSameQuestion()
        {
            var quizManager = new QuizManager();

            var quiz = new MemberTrack.Data.Entities.Quizzes.Quiz
            {
                Id   = 1,
                Name = "What Star Wars character are you?",
            };

            var question = new Question {
                Id = 10, QuizId = quiz.Id, Quiz = quiz
            };
            var question2 = new Question {
                Id = 11, QuizId = quiz.Id, Quiz = quiz
            };

            var allAnswers = new List <Answer>
            {
                new Answer
                {
                    Id         = 100,
                    QuestionId = question.Id,
                    Question   = question
                },
                new Answer
                {
                    Id         = 101,
                    QuestionId = question2.Id,
                    Question   = question2
                },
                new Answer
                {
                    Id         = 102,
                    QuestionId = question.Id,
                    Question   = question
                },
            };

            var answerIds = new List <long> {
                100, 101
            };

            quizManager.ValidateAnswers(quiz, allAnswers, answerIds);
        }
예제 #3
0
        public void NextQuestion_No_RandomizeQuestions()
        {
            var randomizer = new FakeReverseOrderRandomizer(100);

            var quizManager = new QuizManager(randomizer);

            var quiz = new MemberTrack.Data.Entities.Quizzes.Quiz
            {
                Id = 10,
                RandomizeQuestions = false,
            };

            var question1 = new Question
            {
                Id     = 1,
                QuizId = quiz.Id,
            };
            var question2 = new Question
            {
                Id     = 2,
                QuizId = quiz.Id,
            };
            var question3 = new Question
            {
                Id     = 3,
                QuizId = quiz.Id,
            };

            quiz.Questions = new List <Question> {
                question1, question2, question3
            };

            var person = new Person
            {
                Id = 100
            };

            var personAnswers = new List <PersonAnswer>();

            var choosenQuestion = quizManager.NextQuestion(quiz, person, quiz.Questions, personAnswers);

            Assert.AreSame(question1, choosenQuestion);
        }
예제 #4
0
        public void NextQuestion_No_RandomizeAnswers()
        {
            var randomizer = new FakeReverseOrderRandomizer(100);

            var quizManager = new QuizManager(randomizer);

            var answer1 = new Answer
            {
                Id = 1000,
            };

            var answer2 = new Answer
            {
                Id = 1001,
            };

            var answer3 = new Answer
            {
                Id = 1002,
            };

            var quiz = new MemberTrack.Data.Entities.Quizzes.Quiz
            {
                Id = 10,
                RandomizeQuestions = false,
            };

            var question1 = new Question
            {
                Id               = 1,
                QuizId           = quiz.Id,
                RandomizeAnswers = false,
                Answers          = new List <Answer> {
                    answer1, answer2, answer3
                },
            };

            var question2 = new Question
            {
                Id     = 2,
                QuizId = quiz.Id,
            };
            var question3 = new Question
            {
                Id     = 3,
                QuizId = quiz.Id,
            };

            quiz.Questions = new List <Question> {
                question1, question2, question3
            };

            var person = new Person
            {
                Id = 100
            };

            var personAnswers = new List <PersonAnswer>();

            var choosenAnswer = quizManager.NextQuestion(quiz, person, quiz.Questions, personAnswers);

            Assert.AreSame(question1, choosenAnswer);
            Assert.AreEqual(question1.Answers.Count, choosenAnswer.Answers.Count);

            //The answers should be in order.
            Assert.AreSame(answer1, question1.Answers.First());
            Assert.AreSame(answer2, question1.Answers.Skip(1).First());
            Assert.AreSame(answer3, question1.Answers.Skip(2).First());
        }