Exemplo n.º 1
0
        public void AddComment_CallsCacheAddCommentWithCorrectArguments_Once()
        {
            //Arrange
            var     author          = "Test";
            var     movieId         = 1;
            var     text            = "Text";
            var     date            = DateTime.MaxValue;
            Comment expectedComment = new Comment {
                Author  = author,
                MovieId = movieId,
                Text    = text,
                Date    = date
            };

            mockUserService.Setup(s => s.GetUserName()).Returns(author);
            mockDateService.Setup(s => s.Now()).Returns(date);
            movieService = new MovieService(
                mockCache.Object,
                mockUserService.Object,
                mockDateService.Object,
                mockMovieRepo.Object
                );

            //Act
            movieService.AddComment(expectedComment);

            //Assert
            mockMovieRepo.Verify(repo => repo.AddComment(It.Is <Comment>(
                                                             comment => (
                                                                 comment.Author == author &&
                                                                 comment.Date == date &&
                                                                 comment.MovieId == movieId &&
                                                                 comment.Text == text
                                                                 ))), Times.Once);
        }
Exemplo n.º 2
0
 public ActionResult AddComment(string content, int movieId)
 {
     if (content.Length > 0)
     {
         _movieService.AddComment(content, movieId, ApplicationUser.Id);
     }
     return(RedirectToAction("Details", new { id = movieId }));
 }
Exemplo n.º 3
0
 public IActionResult AddComment([FromBody] Comment comment)
 {
     if (ModelState.IsValid)
     {
         var addedComment = MovieService.AddComment(comment);
         return(Created("Comment added", addedComment));
     }
     else
     {
         return(BadRequest());
     }
 }