Exemplo n.º 1
0
        public void Start_WhenQuizCreated_ReturnsOkResultWithQuiz()
        {
            // Arrange
            var quizTemplateStub = new QuizTemplate()
            {
                Id = 1
            };

            var mockQuizTemplateRepo = new Mock <IQuizTemplateRepository>();

            mockQuizTemplateRepo.Setup(repo => repo.GetByID(It.IsAny <int>()))
            .Returns(quizTemplateStub);

            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(uow => uow.QuizTemplateRepository)
            .Returns(mockQuizTemplateRepo.Object);

            var quizStub = new Quiz()
            {
                Id = 1
            };
            var mockManager = new Mock <IQuizFlowManager>();

            mockManager.Setup(manager => manager.StartNewQuiz(It.IsAny <QuizTemplate>()))
            .Returns(quizStub);

            var controller = new QuizFlowController(mockManager.Object, mockUow.Object);

            // Act
            var response = controller.Start(1);

            // Assert
            mockManager.Verify(mock => mock.StartNewQuiz(quizTemplateStub), Times.Once);
            var objectResult = Assert.IsType <OkObjectResult>(response);
            var quiz         = Assert.IsType <Quiz>(objectResult.Value);

            Assert.Equal(1, quiz.Id);
        }
Exemplo n.º 2
0
        public void Start_WhenQuizTemplateNotFound_ThrowsEntityNotFound()
        {
            // Arrange
            var mockQuizTemplateRepo = new Mock <IQuizTemplateRepository>();

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

            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(uow => uow.QuizTemplateRepository)
            .Returns(mockQuizTemplateRepo.Object);

            var mockManager = new Mock <IQuizFlowManager>();

            var controller = new QuizFlowController(mockManager.Object, mockUow.Object);

            // Act & Assert
            var ex = Assert.Throws <EntityNotFoundException>(() => controller.Start(1));

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