Example #1
0
        public void CompleteQuiz_WhenActiveQuiz_LaunchScoreCalculation()
        {
            // Arrange
            var quiz  = new Quiz();
            var score = new Score();

            var mockScoreRepo = new Mock <IScoreRepository>();
            var mockUow       = new Mock <IUnitOfWork>();

            mockUow.Setup(uow => uow.ScoreRepository).Returns(mockScoreRepo.Object);

            var mockScoreFactory = MockDefaultScoreCalculationFactory(score);

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

            // Act
            manager.CompleteQuiz(quiz);

            // Assert
            mockScoreFactory.Verify(f => f.CreateStrategy(quiz), Times.Once);
            mockScoreRepo.Verify(repo => repo.Insert(score), Times.Once);
            Assert.NotNull(quiz.DateEnd);
        }
Example #2
0
        public void CompleteQuiz_WhenQuizAlredyCompleted_ThrowsQuizFlow()
        {
            // Arrange
            var quiz = new Quiz()
            {
                DateStart = DateTime.Now,
                DateEnd   = DateTime.Now
            };
            var score = new Score();

            var mockScoreRepo = new Mock <IScoreRepository>();
            var mockUow       = new Mock <IUnitOfWork>();

            mockUow.Setup(uow => uow.ScoreRepository).Returns(mockScoreRepo.Object);

            var mockScoreFactory = MockDefaultScoreCalculationFactory(score);

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

            // Act & Assert
            var ex = Assert.Throws <QuizFlowException>(() => manager.CompleteQuiz(quiz));

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