public void DeleteMovie_CallWithNoneExistingCategoryId_ShouldReturnNotFoundResult() { // Act var badResponse = _moviesController.DeleteMovie(99); // Assert Assert.IsInstanceOfType(badResponse, typeof(NotFoundResult)); }
public void DeleteMovieBadRequest() { mock.Setup(x => x.DeleteMovie(It.IsAny <int>())).Throws(new ArgumentException()); var result = api.DeleteMovie(It.IsAny <int>()); var objectResult = result as ObjectResult; var statusCode = objectResult.StatusCode; mock.VerifyAll(); Assert.AreEqual(400, statusCode); }
public async Task DeleteNonExistingMovie_NoDeleteWasCalled_ReturnsNotFound() { //Arrange _mockMovieRepository.Setup(x => x.GetAsync(It.IsAny <int>())).Returns(Task.FromResult <Movie>(null)); //Act IActionResult result = await _controller.DeleteMovie(1); //Assert _mockMovieRepository.Verify(x => x.Delete(It.IsAny <Movie>()), Times.Never()); _mockMovieRepository.Verify(x => x.SaveAsync(), Times.Never()); Assert.IsType <NotFoundResult>(result); }
public void DeleteMovies_Returns_NoContentResult() { // 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(), }; movieRepositoryMock.Setup(repo => repo.MovieExist(It.IsAny <Guid>())).Returns(true); movieRepositoryMock.Setup(repo => repo.GetMovie(It.IsAny <Guid>())).Returns(movieModel); movieRepositoryMock.Setup(repo => repo.DeleteMovie(It.IsAny <MovieModel>())).Returns(true); // Act var subGenreResult = movieApiController.DeleteMovie(movieModel.Id); var noContentResult = subGenreResult as NoContentResult; // Assert Assert.True(noContentResult.StatusCode is StatusCodes.Status204NoContent); }
public void TestDeleteMovie() { _moviesController.DeleteMovie(1); try { _context.Movies.Select(x => x).First(y => y.MovieId == 1); Assert.IsTrue(false); } catch (Exception exception) { } try { _context.ActorsMovies.Select(y => y).First(z => z.MovieId == 1); Assert.IsTrue(false); } catch (Exception exception) { Assert.IsTrue(true); } }
public async void TestDeleteMovieWhenIdIsWrong() { int id = -5; var mockRepo = new Mock <IMovieRepository>(); mockRepo.Setup(repo => repo.GetMovie(id)).Returns((MovieDTO)null); var controller = new MoviesController(mockRepo.Object); var result = await controller.DeleteMovie(id); Assert.Contains(HttpStatusCode.BadRequest.ToString(), result.Result.ToString()); }
public async void DeleteMovie_Test() { // Arrange var mapper = new Mock <IMapper>(); var repository = new Mock <ICloudRepository>(); repository.Setup(x => x.Delete(It.IsAny <Movie>())); var controller = new MoviesController(repository.Object, mapper.Object); //Act await controller.DeleteMovie(It.IsAny <int>()); //Assert repository.Verify(x => x.Delete(It.IsAny <Movie>())); }
public async Task CanDeleteMovie() { var result = await _controller.DeleteMovie(2); result.Should().BeOfType <OkObjectResult>(); }