Esempio n. 1
0
        public void TestAnswerStatistic()
        {
            // Prepare data
            List <QuizChoice> choices = new List <QuizChoice>();

            QuizChoice choice1 = new QuizChoice();

            choice1.QuizChoiceID = 1;
            choice1.Choice       = "A";
            choice1.QuestionID   = 1;

            QuizChoice choice2 = new QuizChoice();

            choice2.QuizChoiceID = 2;
            choice2.Choice       = "B";
            choice2.QuestionID   = 1;
            choice2.QuizAnswers.Add(new QuizAnswer());
            choice2.QuizAnswers.Add(new QuizAnswer());

            choices.Add(choice1);
            choices.Add(choice2);

            mockUow.Setup(x => x.QuizChoiceRepository.GetAll()).Returns(choices.AsQueryable());

            // Test
            string jsonResult = facade.GetAnswerStatistic(1);

            Assert.AreEqual("[{\"QuizChoiceID\":1,\"Count\":0},{\"QuizChoiceID\":2,\"Count\":2}]", jsonResult);
        }
Esempio n. 2
0
        public void Start(int quizId)
        {
            log.Debug("Initiate live quiz start, quizId: " + quizId);

            _quiz.Start(quizId);
            QuizQuestion firstQuestion = _quiz.GetCurrentQuestion(quizId);

            LiveQuizModelView question = MapQuizToViewModel(firstQuestion);

            Clients.All.setQuestion(quizId, JsonConvert.SerializeObject(question));
            log.Debug("Broadcast question: " + JsonConvert.SerializeObject(question));

            if (question != null)
            {
                string stats = _quiz.GetAnswerStatistic(question.QuestionID);
                Clients.All.setStats(quizId, stats);
                log.Debug("Broadcast answer statistic: " + stats);
            }
        }