Esempio n. 1
0
        public async Task InsertAnswerUnauthorized()
        {
            UpdateQuizAttemptStatusResult result;

            using (var context = new QuizContext(ManagerTestHelper.Options))
            {
                var logManager = Mock.Of <ILogManager>();
                var quizData   = await ManagerTestHelper.CreateQuizAsync(context, 3, 5);

                var quiz = await context.Quizes.FindAsync(quizData.QuizId);

                var userId = await ManagerTestHelper.AssignQuizAsync(context, quiz.QuizIdentityId);

                var sut = new QuizAttemptManager(context, new QuestionManager(context, logManager), logManager);

                result = await sut.InsertAnswerAsync(userId, 8,
                                                     new Models.TransferObjects.Answer
                {
                    QuestionId = quizData.QuestionIds[0],
                    Options    = quizData.OptionIds.Take(2),
                    TimeSpent  = 40
                });
            }

            Assert.AreEqual(UpdateQuizAttemptStatusResult.NotAuthorized, result);
        }
Esempio n. 2
0
        public async Task InsertAnswer()
        {
            UpdateQuizAttemptStatusResult result;
            QuizAttempt attempt;
            List <int>  optionIds;
            List <int>  answers;
            List <int>  answersOtherQuestion;

            using (var context = new QuizContext(ManagerTestHelper.Options))
            {
                var logManager = Mock.Of <ILogManager>();
                var quizData   = await ManagerTestHelper.CreateQuizAsync(context, 3, 5);

                var quiz = await context.Quizes.FindAsync(quizData.QuizId);

                var userId = await ManagerTestHelper.AssignQuizAsync(context, quiz.QuizIdentityId);

                var sut = new QuizAttemptManager(context, new QuestionManager(context, logManager), logManager);
                var createAttemptResult = await sut.CreateAttempt(userId, quiz.Id);

                attempt   = createAttemptResult.Attempt;
                optionIds = quizData.OptionIds.Skip(2).Take(2).ToList();

                await sut.InsertAnswerAsync(userId, attempt.Id,
                                            new Models.TransferObjects.Answer
                {
                    QuestionId = quizData.QuestionIds[0],
                    Options    = quizData.OptionIds.Take(2),
                    TimeSpent  = 40
                });

                result = await sut.InsertAnswerAsync(userId, attempt.Id,
                                                     new Models.TransferObjects.Answer
                {
                    QuestionId = quizData.QuestionIds[0],
                    Options    = optionIds,
                    TimeSpent  = 40
                });

                answers = context.Answers
                          .Where(a => a.AttemptId == attempt.Id && a.QuestionId == quizData.QuestionIds[0])
                          .Select(a => a.OptionId)
                          .ToList();

                answersOtherQuestion = context.Answers
                                       .Where(a => a.AttemptId == attempt.Id && a.QuestionId == quizData.QuestionIds[1])
                                       .Select(a => a.OptionId)
                                       .ToList();
            }

            Assert.AreEqual(UpdateQuizAttemptStatusResult.Success, result);
            Assert.AreEqual(0, optionIds.Except(answers).ToList().Count);
            Assert.AreEqual(0, answers.Except(optionIds).ToList().Count);
            Assert.AreEqual(0, answersOtherQuestion.Count);
            Assert.AreEqual(40, attempt.TimeSpent);
        }
Esempio n. 3
0
        public async Task FinishQuiz()
        {
            CreateAttemptResponse result;

            using (var context = new QuizContext(ManagerTestHelper.Options))
            {
                var logManager = Mock.Of <ILogManager>();
                var quizData   = await ManagerTestHelper.CreateQuizAsync(context, 3, 5);

                var quiz = await context.Quizes.FindAsync(quizData.QuizId);

                var userId = await ManagerTestHelper.AssignQuizAsync(context, quiz.QuizIdentityId);

                var sut = new QuizAttemptManager(context, new QuestionManager(context, logManager), logManager);
                result = await sut.CreateAttempt(userId, quiz.Id);

                await sut.FinishQuizAsync(result.Attempt, quiz.PassScore, 30);
            }

            Assert.AreEqual(CreateAttemptResult.Success, result.Result);
            Assert.AreEqual(QuizAttemptStatus.Completed, result.Attempt.Status);
            Assert.IsNotNull(result.Attempt.EndDate);
        }