public void DeleteGenre_Returns_NoContent()
        {
            // Arrange
            var genreRepositoryMock = new Mock <IGenreRepository>();
            var genreIMapperMock    = new MapperConfiguration(config =>
            {
                config.AddProfile(new MovieMapper());
            });
            var genreMapper = genreIMapperMock.CreateMapper();
            var logMock     = new Mock <ILogger <GenresController> >();
            ILogger <GenresController> logger = logMock.Object;

            GenresController genreApiController = new
                                                  GenresController(genreRepositoryMock.Object, mapper: genreMapper, logger);
            var genreModel = new GenreModel()
            {
                Name        = "Comedy",
                DateCreated = DateTime.Parse("15 May 2015"),
                Id          = new Guid()
            };

            genreRepositoryMock.Setup(repo => repo.GenreExist(It.IsAny <Guid>()))
            .Returns(true);
            genreRepositoryMock.Setup(repo => repo.GetGenre(It.IsAny <Guid>()))
            .Returns(genreModel);
            genreRepositoryMock.Setup(repo => repo.DeleteGenre(It.IsAny <GenreModel>()))
            .Returns(true);

            // Act
            var genreResult     = genreApiController.DeleteGenre(genreModel.Id);
            var noContentResult = genreResult as NoContentResult;

            // Assert
            Assert.True(noContentResult.StatusCode is StatusCodes.Status204NoContent);
        }
示例#2
0
        public void DeleteGenre_should_delete_genre()
        {
            //Act
            var actionResult = _genresController.DeleteGenre(It.IsAny <int>());

            //Assert
            actionResult.Should().BeOfType <OkNegotiatedContentResult <string> >();
        }
示例#3
0
        public async void TestDeleteGenreWhenIdIsWrong()
        {
            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.DeleteGenre(id);

            Assert.Contains(HttpStatusCode.BadRequest.ToString(), result.Result.ToString());
        }
示例#4
0
        public async Task DeleteGenre_NegativeId_NotFoundResult()
        {
            // Arrange
            const int genreIdToDelete = -10;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Genre expectedGenre = GetFakeList().Where(d => d.ID == genreIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var actionResult = (await genresController.DeleteGenre(genreIdToDelete));
                var result       = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
示例#5
0
        public async Task DeleteGenre_ExistingId_TaskActionResultContainsDeletedGenre()
        {
            // Arrange
            const int genreIdToDelete = 3;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Genre expectedGenre = GetFakeList().Where(d => d.ID == genreIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GenresController genresController = new GenresController(context);
                var   actionResult = (await genresController.DeleteGenre(genreIdToDelete));
                var   result       = actionResult.Result;
                Genre actualGenre  = actionResult.Value;

                // Assert
                Assert.IsNotType <NotFoundResult>(result);
                Assert.True(context.Genres.Find(genreIdToDelete) == null);
                Assert.True(AreEqual(expectedGenre, actualGenre));
            }
        }