public async Task Delete_ValidMovieId_ReturnsOk() { movieRepositoryMock.Setup(mr => mr.DeleteMovie(1)).ReturnsAsync(Constants.SUCCESS); var response = await movieController.Delete(1) as OkResult; Assert.Equal(200, response.StatusCode); }
public async Task Test_MovieController_DeleteById_Should_Be_Ok() { var fakeId = 1; movieServiceMock.Setup(ms => ms.Delete(fakeId)).Returns(Task.CompletedTask); var apiResult = await movieController.Delete(fakeId); apiResult.Should().BeOfType <AcceptedResult>(); movieServiceMock.Verify(ms => ms.Delete(fakeId), Times.Once); movieServiceMock.VerifyNoOtherCalls(); }
public void Delete() { // Arrange MovieController controller = new MovieController(); // Act ViewResult result = controller.Delete(1) as ViewResult; // Assert Assert.IsNotNull(result); }
public static bool MovieDeleteValidation(int id) { try { MovieController.Delete(id); return(true); } catch (Exception e) { return(false); } }
public async Task Delete_ReturnsNoContentResult_WhenMovieIsNull() { var mapper = CreateAutomapper(); var movieServiceMock = new Mock <IMovieService>(); movieServiceMock.Setup(s => s.GetByIdAsync(It.IsAny <long>())).Returns(Task.FromResult((Movie)null)); var controller = new MovieController(mapper, movieServiceMock.Object); var result = await controller.Delete(1); var noContentResult = Assert.IsType <NoContentResult>(result); }
public void Post_ShouldUnRecommendMovieAsExpected() { // Arrange var movieId = 901; this.mockService.Setup(x => x.DeleteRecommendation(It.IsAny <int>())).Verifiable(); var controller = new MovieController(mockService.Object); // Act var result = controller.Delete(movieId) as StatusCodeResult; //Assert Assert.NotNull(result); Assert.Equal(200, result.StatusCode); }
public void DeleteMethod_ShouldReturnNotFoundtOnInValidId() { //arrange int movieId = 10011; var mockRepo = new Mock <IMovieService>(); mockRepo.Setup(x => x.DeleteMovie(movieId)).Throws <System.ArgumentException>(); var controller = new MovieController(mockRepo.Object); //act var actual = controller.Delete(movieId); //assert var result = Assert.IsType <NotFoundObjectResult>(actual); }
public void DeleteMethod_ShouldReturnOkResultOnValidId() { //arrange int movieId = 10001; var mockRepo = new Mock <IMovieService>(); mockRepo.Setup(x => x.DeleteMovie(movieId)); var controller = new MovieController(mockRepo.Object); //act var actual = controller.Delete(movieId); //assert Assert.IsType <OkResult>(actual); }
public void Delete_ShouldNotDeleteMovieForGivenId() { var expected = false; var mockService = new Mock <IMovieService>(); mockService.Setup(x => x.DeleteMovie(It.IsAny <int>())).Returns(expected); var controller = new MovieController(mockService.Object); var result = controller.Delete(126); //Assert var actionResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, actionResult.StatusCode); }
public void Delete_WithMovieFound_ReturnsView() { IMembershipService membershipService = new FakeMembershipService(Enumerable.Empty <MembershipUser>()); var movies = new List <Movie>(); const int movieId = 42; movies.Add(new Movie { Id = movieId }); IRepository <Movie> movieRepository = new FakeMovieRepository(movies); IRepository <Genre> genreRepository = new FakeGenreRepository(); var movieController = new MovieController(movieRepository, genreRepository, membershipService); var result = movieController.Delete(movieId) as ViewResult; Assert.IsNotNull(result); }
public void Delete_Returns_Success() { //Arrange var mockrepo = new Mock <IMovieRepository>(); mockrepo.Setup(repo => repo.Remove(354440)); var controller = new MovieController(mockrepo.Object); //Act var result = controller.Delete(354440); //Assert var actionresult = Assert.IsType <ObjectResult>(result); Assert.Equal(202, actionresult.StatusCode); var model = Assert.IsAssignableFrom <ApiResponse>(actionresult.Value); Assert.True(model.Success); }
public void Delete_ShouldDeleteMovieForGivenId() { var allMovies = GetAllMovies(); var beforeDeleted = allMovies.Count; var expected = allMovies.Remove(allMovies.FirstOrDefault(x => x.Id == 126)); var actualCount = allMovies.Count; var mockService = new Mock <IMovieService>(); mockService.Setup(x => x.DeleteMovie(It.IsAny <int>())).Returns(expected); var controller = new MovieController(mockService.Object); var result = controller.Delete(126); //Assert var actionResult = Assert.IsType <OkObjectResult>(result); var response = Assert.IsAssignableFrom <List <Movie> >(allMovies); Assert.Equal(200, actionResult.StatusCode); Assert.NotEqual(beforeDeleted, actualCount); }
public async Task Delete_ReturnsNoContentResultAndDeletesMovie() { var mapper = CreateAutomapper(); var movieServiceMock = new Mock <IMovieService>(); movieServiceMock.Setup(s => s.GetByIdAsync(It.IsAny <long>())) .Returns(Task.FromResult(new Movie())) .Verifiable(); movieServiceMock.Setup(s => s.DeleteAsync(It.IsAny <long>())) .Returns(Task.FromResult((long)1)) .Verifiable(); var controller = new MovieController(mapper, movieServiceMock.Object); var result = await controller.Delete(1); var noContentResult = Assert.IsType <NoContentResult>(result); movieServiceMock.Verify(); }
public void Delete_WithValidMovie_CallsSaveOnMovieRepository() { var users = new List <MembershipUser>(); Guid guid = Guid.NewGuid(); users.Add(new TestMembershipUser("test", guid)); IMembershipService membershipService = new FakeMembershipService(users); var movies = new List <Movie>(); const int movieId = 42; movies.Add(new Movie { Id = movieId }); bool wasCalled = false; Action saveAction = () => wasCalled = true; IRepository <Movie> movieRepository = new FakeMovieRepository(movies, saveCallback: saveAction); IRepository <Genre> genreRepository = new FakeGenreRepository(); var movieController = new MovieController(movieRepository, genreRepository, membershipService); var movie = new Movie { Id = movieId, Directors = "Directors", GenreId = 1, Name = "Name", Rating = 3, Stars = "Stars", Writers = "Writers" }; movieController.Delete(movie); Assert.IsTrue(wasCalled); }
private void RemoveMovie() { this.DeleteCmdDisplay(); movieController.Delete(); this.ReturnToMainScreen(); }