Example #1
0
        public void GetNextQuestion_WhenNoNextQuestionFound_ReturnsQuizFinishCommand()
        {
            // Arrange
            var quiz                     = new Quiz();
            var mockQuizRepo             = new Mock <IQuizRepository>();
            var mockQuestionTemplateRepo = new Mock <IQuestionTemplateRepository>();

            mockQuestionTemplateRepo.Setup(repo => repo.GetQuestionTemplate(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(value: null);

            var mockUow = new Mock <IUnitOfWork>();

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

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

            // Act
            var command = manager.GetNextQuestion(quiz);

            // Assert
            var commandFinish = Assert.IsType <QuizFlowCommandFinishContract>(command);
        }
Example #2
0
        public void GetNextQuestion_WhenCurrentQuestionNotAnswered_ReturnsQuizProceedCommandWithCurrentQuestion()
        {
            // Arrange
            var quiz = new Quiz()
            {
                Id = 1
            };
            var currentQuestion = new Question()
            {
                Id   = 2,
                Quiz = quiz
            };

            quiz.Questions.Add(currentQuestion);

            var questionTemplate = new QuestionTemplate();

            questionTemplate.Answers.Add(new AnswerTemplate()
            {
                IsCorrect = false
            });
            questionTemplate.Answers.Add(new AnswerTemplate()
            {
                IsCorrect = true
            });

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

            mockQuestionTemplateRepo
            .Setup(repo => repo.GetByID(It.IsAny <int>()))
            .Returns(questionTemplate);

            var mockUow = new Mock <IUnitOfWork>();

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

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

            // Act
            var command = manager.GetNextQuestion(quiz);

            // Assert
            var commandProceed = Assert.IsType <QuizFlowCommandProceedContract>(command);

            Assert.Equal(1, commandProceed.QuizId);
            Assert.Equal(2, commandProceed.QuestionId);
            Assert.Equal(2, commandProceed.Template.Answers.Count);
            Assert.DoesNotContain(commandProceed.Template.Answers, answer => answer.IsCorrect);
        }
Example #3
0
        public void GetNextQuestion_WhenQuizCompleted_ThrowsQuizFlow()
        {
            // Arrange
            var quizStub = new Quiz()
            {
                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.GetNextQuestion(quizStub));

            Assert.Equal(QuizFlowErrorCodes.QuizAlreadyCompleted.ToString(), ex.ErrorCode);
        }