Пример #1
0
        public async Task PutGenre_ExistingIdCorrectGenreWithNameChanged_NoContentResult()
        {
            // Arrange
            const int genreId = 3;

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

            Genre genreToUpdate = GetFakeList().Where(d => d.ID == genreId).FirstOrDefault(),
            // Should use ICopyable interface here
                  expectedGenre = GetFakeList().Where(d => d.ID == genreId).FirstOrDefault();


            // Act
            using (var context = new GameReviewsContext(options))
            {
                genreToUpdate.Name = "newName";
                expectedGenre.Name = "newName";

                GenresController genresController = new GenresController(context);
                var result = (await genresController.PutGenre(genreId, genreToUpdate));

                Genre actualGenre = await context.Genres.Where(d => d.ID == genreId).FirstOrDefaultAsync();

                // Assert
                Assert.True(AreEqual(expectedGenre, actualGenre));
                Assert.IsType <NoContentResult>(result);
            }
        }
Пример #2
0
        public async void TestPutGenreWhenObjectIsNull()
        {
            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.PutGenre(id, genre : null);

            Assert.Contains(HttpStatusCode.BadRequest.ToString(), result.ToString());
        }
Пример #3
0
        public async Task PutGenre_ExistingIdCorrectGenreWithIdChangedNegative_BadRequestResult()
        {
            // Arrange
            const int genreId = 3, idChanged = -1;

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

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

            // Act
            using (var context = new GameReviewsContext(options))
            {
                genreToUpdate.ID = idChanged;

                GenresController genresController = new GenresController(context);
                var result = (await genresController.PutGenre(genreId, genreToUpdate));

                Genre actualGenre = await context.Genres.Where(d => d.ID == genreId).FirstOrDefaultAsync();

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