Пример #1
0
        public void GetScore_WhenScoreFound_ReturnsOkResultWithScore()
        {
            // Arrange
            var scoreStub = new Score()
            {
                Id = 1
            };

            var mockScoreRepo = new Mock <IScoreRepository>();

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

            var mockUow = new Mock <IUnitOfWork>();

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

            var controller = new ScreenController(mockUow.Object);

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

            // Assert
            var objectResult = Assert.IsType <OkObjectResult>(response);
            var score        = Assert.IsType <Score>(objectResult.Value);

            Assert.Equal(1, score.Id);
        }
Пример #2
0
        public void GetScore_WhenScoreNotFound_ThrowsEntityNotFound()
        {
            // Arrange
            var mockScoreRepo = new Mock <IScoreRepository>();

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

            var mockUow = new Mock <IUnitOfWork>();

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

            var controller = new ScreenController(mockUow.Object);

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

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