public void DeleteMovieTest() { MovieDTO inputMovie = TestingHelper.GetRandomMovie(); Movie outputMovie; using (var context = new Cinephiliacs_MovieContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); TestingHelper.AddMovieDTOToDatabase(context, inputMovie); RepoLogic repoLogic = new RepoLogic(context); IMovieLogic movieLogic = new MovieLogic(repoLogic); MovieController movieController = new MovieController(movieLogic); // Test DeleteMovie() movieController.DeleteMovie(inputMovie.ImdbId); } using (var context = new Cinephiliacs_MovieContext(dbOptions)) { outputMovie = context.Movies.FirstOrDefault(m => m.ImdbId == inputMovie.ImdbId); } Assert.Null(outputMovie); }
public void DeleteMovie() { // Arrange MovieController controller = new MovieController(); // Act IHttpActionResult result = controller.DeleteMovie(3) as IHttpActionResult; // Assert Assert.IsNotNull(result); }
protected void deletebtn_Click(object sender, EventArgs e) { Movie m = new Movie(); m.Id = Convert.ToInt32(idtxt.Text); movie_controller.DeleteMovie(m); idtxt.Enabled = true; string msg = "Are you sure you want to delete?"; System.Web.HttpContext.Current.Response.Write("<SCRIPT>alert('" + msg + "')</SCRIPT>"); statuslbl.Text = "Record Deleted"; }
public async void DeletesMovie() { var context = InMemoryDbContextFactory.GetDbContext(); context.Add(new Movie { MovieId = 1, Title = "Testing Movie1" }); await context.SaveChangesAsync(); var controller = new MovieController(context); var response = await controller.DeleteMovie(1); Assert.IsType <OkObjectResult>(response.Result); var okRes = (OkObjectResult)response.Result; Assert.Equal("Testing Movie1", ((Movie)okRes.Value).Title); }
public void DeleteMovie_MovieDoesNotExists() { var movie = new Movie { Id = 1, Name = "movie1", Comments = "comments1", PosterPath = "path1", ReleaseDate = "releaseDate1", VoteAverage = 5.00, VoteCount = 100 }; Movie deletedMovie = null; var mockService = new Mock <IMovieService>(); mockService.Setup(service => service.GetMovie(movie.Id)).Returns(deletedMovie); var mockController = new MovieController(mockService.Object); var result = mockController.DeleteMovie(movie.Id); var actionResult = Assert.IsType <NotFoundObjectResult>(result); Assert.Equal <int>(404, actionResult.StatusCode.Value); }
public void DeleteMovie_MovieIsDeleted() { var mockService = new Mock <IMovieService>(); var movie = new Movie { Id = 5, Name = "Movie Test", Comments = "comments1", PosterPath = "pp.jpg", ReleaseDate = "releaseDate1", VoteAverage = 5.00, VoteCount = 100 }; List <Movie> addedMovies = new List <Movie> { movie }; mockService.Setup(service => service.GetMovie(movie.Id)).Returns(movie); mockService.Setup(service => service.DeleteMovie(movie.Id)).Callback <int>((id) => addedMovies.Remove(addedMovies.Single(m => m.Id == id))); var controller = new MovieController(mockService.Object); var result = controller.DeleteMovie(movie.Id); var actionResult = Assert.IsType <OkObjectResult>(result); Assert.True(0 == addedMovies.Count); }
public static async Task DeleteMovieAsync(string title) { Dictionary <string, string> parameters = new Dictionary <string, string> { { "Title", title } }; FormUrlEncodedContent encodedContent = new FormUrlEncodedContent(parameters); using (HttpResponseMessage response = await MovieController.DeleteMovie(encodedContent)) { int status = (int)response.StatusCode; string body = await response.Content.ReadAsStringAsync(); if (status == 200) { return; } else if (status == 400) { throw new Exception(body); } else if (status == 401) { throw new UnauthenticatedException(); } else if (status == 403) { throw new UnauthorizedException(); } else if (status == 500) { throw new ServerException(); } else { throw new Exception("An uncaught error occurred."); } } }