public void CreateMovie_Returns_CreatedAtRouteResult() { // Arrange var movieRepositoryMock = new Mock <IMovieRepository>(); var subGenreIMapperMock = new MapperConfiguration(config => { config.AddProfile(new MovieMapper()); }); var movieMapper = subGenreIMapperMock.CreateMapper(); MoviesController movieApiController = new MoviesController(movieRepositoryMock.Object, mapper: movieMapper); var movieModel = new MovieModel() { Name = "Adult Content", DateCreated = DateTime.Parse("15 May 2015"), Id = Guid.NewGuid(), GenreId = Guid.NewGuid(), Genres = new GenreModel(), }; var movieDto = new MoviesCreateDTO() { Name = movieModel.Name, DateCreated = movieModel.DateCreated, GenreId = movieModel.GenreId, SubGenreId = Guid.NewGuid() }; movieRepositoryMock.Setup(repo => repo.MovieExist(It.IsAny <string>())).Returns(false); movieRepositoryMock.Setup(repo => repo.CreateMovie(It.IsAny <MovieModel>())).Returns(true); // Act var movieResult = movieApiController.CreateMovie(movieDto); var createdAtRouteResult = movieResult as CreatedAtRouteResult; // Assert Assert.True(createdAtRouteResult.StatusCode is StatusCodes.Status201Created); }
public void CreateMovie_ReturnNotFoundResult() { var controller = new MoviesController(_dataService, _loggerFactory); var result = controller.CreateMovie(_allMovies.First()); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public void CreateMovie_ReturnInternalServerError_WhenDataServiceThrowsException() { Mock.Get(_dataService).Setup(d => d.CreateMovie(It.IsAny <MovieDto>())) .Throws(new Exception()); var controller = new MoviesController(_dataService, _loggerFactory); var result = controller.CreateMovie(_allMovies.First()); Assert.IsInstanceOfType(result, typeof(StatusCodeResult)); var statusCode = result as StatusCodeResult; Assert.IsTrue(statusCode.StatusCode == StatusCodes.Status500InternalServerError); }
public void CreateMovie_ReturnBadRequestObjectResult() { var controller = new MoviesController(_dataService, _loggerFactory); controller.ModelState.Clear(); controller.ModelState.AddModelError("Title", "The Title field is required."); var invalidMovie = new MovieDto(); invalidMovie.MovieId = 1; var result = controller.CreateMovie(invalidMovie); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); }
public void AddMovie_ValidInput_ReturnsTheValidMovie() { // Arrange var movie = new Movie { Id = 14, Author = "Abraham", Rating = 1, Name = "Test2", Description = "some desc", Edition = "5" }; _mockRepository.Setup(x => x.AddMovie(movie)).Returns(movie); // Act var actionResult = _controller.CreateMovie(movie); var contentResult = actionResult as OkNegotiatedContentResult <Movie>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); }
public void CreateMovie_ReturnOkResult() { Mock.Get(_dataService).Setup(d => d.CreateMovie(It.IsAny <MovieDto>())) .Returns(_allMovies.First(m => m.MovieId == 1)); var controller = new MoviesController(_dataService, _loggerFactory); var result = controller.CreateMovie(_allMovies.First(m => m.MovieId == 1)); var contentResult = result as CreatedAtActionResult; Assert.IsTrue(contentResult.StatusCode == StatusCodes.Status201Created); Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Value); var resultMovie = contentResult.Value as MovieDto; Assert.IsNotNull(resultMovie); }