Beispiel #1
0
        public async Task PostGenre_CorrectGenreWithCorrectValuesAndNonexistingIdSetted_CreatedAtActionResultWithSettedId()
        {
            // Arrange
            const int idToSet = 10;

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

            Genre genreToCreate = new Genre()
            {
                Name = "NewDevelope",
                ID   = idToSet
            };

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

                // Assert
                Assert.True(context.Genres.Contains(genreToCreate));
                Assert.True(genreToCreate.ID == idToSet);
                Assert.IsType <CreatedAtActionResult>(result);
            }
        }
Beispiel #2
0
        public async void TestInsertGenreWhenObjectIsNull()
        {
            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 = await controller.PostGenre(genre : null);

            Assert.Contains(HttpStatusCode.BadRequest.ToString(), result.Result.ToString());
        }
Beispiel #3
0
        public async Task PostGenre_CorrectGenreWithCorrectValuesAndNegativeIdSetted_BadRequestResult()
        {
            // Arrange
            const int idToSet = -1;

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

            Genre genreToCreate = new Genre()
            {
                Name = "NewDevelope",
                ID   = idToSet
            };

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

                // Assert
                Assert.IsType <BadRequestResult>(result);
            }
        }