Exemplo n.º 1
0
        public void AnswerQuestion_WhenAnswerTemplateFound_SetQuestionAnswered()
        {
            // Arrange
            var questionStub = new Question();
            var answerStub   = new AnswerTemplate()
            {
                Id        = 1,
                IsCorrect = true
            };
            var questionTemplateStub = new QuestionTemplate();

            questionTemplateStub.Answers.Add(answerStub);

            var mockQuizRepo             = new Mock <IQuizRepository>();
            var mockQuestionTemplateRepo = new Mock <IQuestionTemplateRepository>();

            mockQuestionTemplateRepo.Setup(repo => repo.GetByID(It.IsAny <int>()))
            .Returns(value: questionTemplateStub);

            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(repo => repo.QuestionTemplateRepository)
            .Returns(mockQuestionTemplateRepo.Object);

            var manager = new QuizFlowManager(mockUow.Object, null);

            // Act
            manager.AnswerQuestion(questionStub, 1);

            // Assert
            Assert.True(questionStub.IsAnswered);
            Assert.Single(questionStub.Answers);
            Assert.True(questionStub.Answers.First().IsCorrect);
        }
Exemplo n.º 2
0
        public void AnswerQuestion_WhenQuestionAlreadyAnswered_ThrowsQuizFlow()
        {
            // Arrange
            var quizStub     = new Quiz();
            var questionStub = new Question()
            {
                Id        = 1,
                DateStart = DateTime.Now,
                DateEnd   = DateTime.Now
            };

            var mockUow = new Mock <IUnitOfWork>();
            var manager = new QuizFlowManager(mockUow.Object, null);

            // Act & Assert
            var ex = Assert.Throws <QuizFlowException>(() => manager.AnswerQuestion(questionStub, 1));

            Assert.Equal(QuizFlowErrorCodes.QuestionAlreadyAnswered.ToString(), ex.ErrorCode);
        }
Exemplo n.º 3
0
        public void AnswerQuestion_WhenAnswerTemplateNotFound_ThrowsEntityNotFound()
        {
            // Arrange
            var questionStub             = new Question();
            var questionTemplateStub     = new QuestionTemplate();
            var mockQuizRepo             = new Mock <IQuizRepository>();
            var mockQuestionTemplateRepo = new Mock <IQuestionTemplateRepository>();

            mockQuestionTemplateRepo.Setup(repo => repo.GetByID(It.IsAny <int>()))
            .Returns(value: questionTemplateStub);

            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(repo => repo.QuestionTemplateRepository)
            .Returns(mockQuestionTemplateRepo.Object);

            var manager = new QuizFlowManager(mockUow.Object, null);

            // Act & Assert
            var ex = Assert.Throws <EntityNotFoundException>(() => manager.AnswerQuestion(questionStub, 1));

            Assert.Equal("AnswerTemplate", ex.EntityType);
            Assert.Equal(1, ex.EntityId);
        }