public async Task UpdatingAMovieWithAnInvalidMovieIdShouldReturnBadRequest() { // Arrange var mockRepo = new Mock <IMoviesRepository>(MockBehavior.Strict); var controller = new MoviesController(mockRepo.Object); // Act var movieRequest = new MovieRequestBuilder().WithValidMovie().Build(); var result = await controller.UpdateMovie("invalid", movieRequest); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task UpdatingAMovieWithAValidMovieIdShouldReturnOk() { // Arrange var mockRepo = new Mock <IMoviesRepository>(MockBehavior.Strict); mockRepo.Setup(repo => repo.UpdateMovie(It.IsAny <Movie>())) .ReturnsAsync(true); var controller = new MoviesController(mockRepo.Object); // Act var movieRequest = new MovieRequestBuilder().WithValidMovie().Build(); var result = await controller.UpdateMovie("5d5fbc449fdf6d3f23ce4510", movieRequest); // Assert Assert.IsType <OkObjectResult>(result); }
public async Task InsertingAValidMovieShouldReturnOk() { // Arrange var mockRepo = new Mock <IMoviesRepository>(MockBehavior.Strict); var movie = new Movie("title", "director", "actors", "image", 2000); mockRepo.Setup(repo => repo.InsertMovie(It.IsAny <Movie>())) .ReturnsAsync(movie); var controller = new MoviesController(mockRepo.Object); // Act var movieRequest = new MovieRequestBuilder().WithValidMovie().Build(); var result = await controller.InsertMovie(movieRequest); // Assert Assert.IsType <OkObjectResult>(result); }
public async Task UpdatingAMovieWithAnInvalidModelShouldReturnBadRequest() { // Arrange var mockRepo = new Mock <IMoviesRepository>(MockBehavior.Strict); mockRepo.Setup(repo => repo.UpdateMovie(It.IsAny <Movie>())) .ReturnsAsync(true); var controller = new MoviesController(mockRepo.Object); // This will cause the validation fails controller.ModelState.AddModelError("Error", "Error"); // Act var movieRequest = new MovieRequestBuilder().WithValidMovie().Build(); var result = await controller.UpdateMovie("5d5fbc449fdf6d3f23ce4510", movieRequest); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task UpdatingAMovieWithALongTitleShouldReturnBadRequest() { // Arrange var mockRepo = new Mock <IMoviesRepository>(MockBehavior.Strict); mockRepo.Setup(repo => repo.UpdateMovie(It.IsAny <Movie>())) .ReturnsAsync(true); var controller = new MoviesController(mockRepo.Object); controller.ModelState.AddModelError("Error", "Error"); // Act // Title longer than 100 var movieRequest = new MovieRequestBuilder().WithValidMovie().WithTitle(new string('a', 1001)).Build(); var result = await controller.UpdateMovie("5d5fbc449fdf6d3f23ce4510", movieRequest); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task InsertingAnInvalidModelShouldReturnBadRequest() { // Arrange var mockRepo = new Mock <IMoviesRepository>(MockBehavior.Strict); var movie = new Movie("title", "director", "actors", "image", 2000); mockRepo.Setup(repo => repo.InsertMovie(It.IsAny <Movie>())) .ReturnsAsync(movie); var controller = new MoviesController(mockRepo.Object); // This will cause the validation fails controller.ModelState.AddModelError("Error", "Error"); // Act var movieRequest = new MovieRequestBuilder().WithValidMovie().Build(); var result = await controller.InsertMovie(movieRequest); // Assert Assert.IsType <BadRequestResult>(result); }