コード例 #1
0
        public async Task GetGenreByIdSuccessfully()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();

            context.Genres.Add(new Genre()
            {
                Name = "Genre 1"
            });
            context.Genres.Add(new Genre()
            {
                Name = "Genre 2"
            });
            context.SaveChanges();

            var context2 = BuildContext(databaseName);

            //Testing
            var id         = 1;
            var controller = new GenresController(context2, mapper);
            var response   = await controller.GetGenre(id);

            //Verification
            var result = response.Value;

            Assert.AreEqual(1, result.Id);
        }
コード例 #2
0
        public void TestGetAllGenres()
        {
            int id       = 5;
            var mockRepo = new Mock <IGenreRepository>();

            mockRepo.Setup(repo => repo.GetGenre(id)).Returns((GenreDTO)null);

            var controller = new GenresController(mockRepo.Object);

            var result = controller.GetGenre();

            Assert.NotNull(result.Result);
        }
コード例 #3
0
        public void TestGetGenreWhenIdIsNotCorrect()
        {
            int id       = 5555;
            var mockRepo = new Mock <IGenreRepository>();

            mockRepo.Setup(repo => repo.GetGenre(id)).Returns((GenreDTO)null);

            var controller = new GenresController(mockRepo.Object);

            var result = controller.GetGenre(id);

            Assert.Null(result.Value);
        }
コード例 #4
0
        public void TestGetGenreWhenIdIsCorrect()
        {
            int id       = 5;
            var mockRepo = new Mock <IGenreRepository>();

            mockRepo.Setup(repo => repo.GetGenre(id)).Returns((GenreDTO)null);

            var controller = new GenresController(mockRepo.Object);

            var result = controller.GetGenre(id);

            Assert.IsType <ActionResult <GenreDTO> >(result);
        }
コード例 #5
0
        public async Task GetGenreByIdDoesNotExist()
        {
            //Preparation
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);
            var mapper       = BuildMap();
            var id           = 1;

            //Testing
            var controller = new GenresController(context, mapper);
            var response   = await controller.GetGenre(id);

            //Verification
            var result = response.Result as StatusCodeResult;

            Assert.AreEqual(404, result.StatusCode);
        }
コード例 #6
0
        public async Task GetGenre_NonexistentZeroId_NotFoundResult()
        {
            // Arrange
            const int genreId = 0;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var result = (await genresController.GetGenre(genreId)).Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
コード例 #7
0
        public void Get_should_return_genre_by_id()
        {
            //Arrange
            int id = It.IsAny <int>();

            _genreService.Setup(x => x.Get(It.IsAny <int>())).Returns(new GenreDTO()
            {
                Id = id
            });

            //Act
            var actionResult = _genresController.GetGenre(It.IsAny <int>());

            //Assert
            actionResult.Should().BeOfType <GenreModel>();
            Assert.AreEqual(id, actionResult.Id);
        }
コード例 #8
0
        public async Task GetGenre_ExistingId_TaskActionResultContainsGenre()
        {
            // Arrange
            const int genreId = 3;

            Genre expectedGenre = GetFakeList().Where(d => d.ID == genreId).FirstOrDefault();

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var          actionResult         = (await genresController.GetGenre(genreId));
                Genre        genre  = actionResult.Value;
                ActionResult result = actionResult.Result;

                // Assert
                Assert.True(AreEqual(expectedGenre, genre));
                Assert.IsNotType <NotFoundResult>(result);
            }
        }