Пример #1
0
        public void GetQuizTemplate_WhenTemplateFound_ReturnsOkResultWithTemplatesDetails()
        {
            // Arrange
            var quizTemplateStub = new QuizTemplate()
            {
                Id = 1
            };

            var mockQuizTemplateRepo = new Mock <IQuizTemplateRepository>();

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

            var mockUow = new Mock <IUnitOfWork>();

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

            var controller = new ScreenController(mockUow.Object);

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

            // Assert
            var objectResult       = Assert.IsType <OkObjectResult>(response);
            var quizTemplateDetail = Assert.IsType <QuizTemplateDetailsContract>(objectResult.Value);

            Assert.Equal(42, quizTemplateDetail.QuestionsCount);
            Assert.NotNull(quizTemplateDetail.QuizTemplate);
            Assert.Equal(1, quizTemplateDetail.QuizTemplate.Id);
        }
Пример #2
0
        public void GetQuizTemplate_WhenTemplateNotFound_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 controller = new ScreenController(mockUow.Object);

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

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