public void CompleteQuiz_WhenValidArguments_ReturnsOkResult() { // Arrange var quiz = new Quiz(); var mockQuizRepo = new Mock <IQuizRepository>(); mockQuizRepo.Setup(repo => repo.GetByID(It.IsAny <int>())) .Returns(value: quiz); var mockUow = new Mock <IUnitOfWork>(); mockUow.Setup(uow => uow.QuizRepository) .Returns(mockQuizRepo.Object); var mockManager = new Mock <IQuizFlowManager>(); mockManager.Setup(manager => manager.CompleteQuiz(It.IsAny <Quiz>())); var controller = new QuizFlowController(mockManager.Object, mockUow.Object); // Act var response = controller.CompleteQuiz(1); // Assert mockManager.Verify(mock => mock.CompleteQuiz(quiz), Times.Once); var objectResult = Assert.IsType <OkResult>(response); }
public void CompleteQuiz_WhenQuizNotFound_ThrowsEntityNotFound() { // Arrange var mockQuizRepo = new Mock <IQuizRepository>(); mockQuizRepo.Setup(repo => repo.GetByID(It.IsAny <int>())) .Returns(value: null); var mockUow = new Mock <IUnitOfWork>(); mockUow.Setup(uow => uow.QuizRepository) .Returns(mockQuizRepo.Object); var mockManager = new Mock <IQuizFlowManager>(); var controller = new QuizFlowController(mockManager.Object, mockUow.Object); // Act & Assert var ex = Assert.Throws <EntityNotFoundException>(() => controller.CompleteQuiz(1)); Assert.Equal("Quiz", ex.EntityType); Assert.Equal(1, ex.EntityId); }