public async Task <IActionResult> Create(CreateMovieCommentInputModel input) { var parentId = input.ParentId == 0 ? (int?)null : input.ParentId; if (parentId.HasValue) { if (!await this.movieCommentsService.IsInMovieId(parentId.Value, input.MovieId)) { return(this.BadRequest()); } } var userId = this.userManager.GetUserId(this.User); try { await this.movieCommentsService.CreateAsync(input.MovieId, userId, input.Content, parentId); } catch (ArgumentException aex) { return(this.BadRequest(aex.Message)); } return(this.RedirectToAction("Details", "Movies", new { id = input.MovieId })); }
public async Task CheckIfAddingMovieCommentThrowsArgumentException() { this.SeedDatabase(); var movieComment = new CreateMovieCommentInputModel { MovieId = this.firstMovie.Id, Content = this.firstMovieComment.Content, }; var exception = await Assert .ThrowsAsync <ArgumentException>(async() => await this.movieCommentsService .CreateAsync(movieComment.MovieId, this.user.Id, movieComment.Content)); Assert.Equal( string.Format( ExceptionMessages.MovieCommentAlreadyExists, movieComment.MovieId, movieComment.Content), exception.Message); }
public async Task TestAddingMovieComment() { await this.SeedUsers(); await this.SeedDirectors(); await this.SeedMovies(); var movieComment = new CreateMovieCommentInputModel { MovieId = this.firstMovie.Id, Content = "I like this movie.", }; await this.movieCommentsService.CreateAsync(movieComment.MovieId, this.user.Id, movieComment.Content); var count = await this.movieCommentsRepository.All().CountAsync(); Assert.Equal(1, count); }
public async Task CheckSettingOfMovieCommentProperties() { await this.SeedUsers(); await this.SeedDirectors(); await this.SeedMovies(); var model = new CreateMovieCommentInputModel { MovieId = this.firstMovie.Id, Content = "What's your opinion for the movie?", }; await this.movieCommentsService.CreateAsync(model.MovieId, this.user.Id, model.Content); var movieComment = await this.movieCommentsRepository.All().FirstOrDefaultAsync(); Assert.Equal(model.MovieId, movieComment.MovieId); Assert.Equal("What's your opinion for the movie?", movieComment.Content); }