public void CreateGenre_Returns_CreatedAtRoute()
        {
            // 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 genreDto = new GenreDTO()
            {
                Name        = "Comedy",
                DateCreated = DateTime.Parse("15 May 2015"),
                Id          = new Guid()
            };

            genreRepositoryMock.Setup(repo => repo.GenreExist(It.IsAny <string>()))
            .Returns(false);
            genreRepositoryMock.Setup(repo => repo.CreateGenre(It.IsAny <GenreModel>()))
            .Returns(true);

            // Act
            var genreResult          = genreApiController.CreateGenre(genreDto);
            var createdAtRouteResult = genreResult as CreatedAtRouteResult;

            // Assert
            Assert.True(createdAtRouteResult.StatusCode is StatusCodes.Status201Created);
        }
Exemple #2
0
        public void CreateGenre_should_create_genre()
        {
            //Act
            var actionResult = _genresController.CreateGenre(new GenreModel());

            //Assert
            actionResult.Should().BeOfType <OkNegotiatedContentResult <string> >();
        }