コード例 #1
0
ファイル: QuoteHelper.cs プロジェクト: MaxShustov/GameStore
 public static MvcHtmlString CreateQuote(this HtmlHelper html, CommentViewModel comment)
 {
     TagBuilder quote = new TagBuilder("quote");
     if (comment.IsWithQuote)
         quote.InnerHtml += html.CreateQuote(comment.ParentComment);
     quote.InnerHtml += comment.Body;
     return new MvcHtmlString(quote.ToString());
 }
コード例 #2
0
        public void Test_NewComment_Try_Add_With_Empty_Body()
        {
            //arrange
            GameController controller = new GameController(_gameService.Object, _commentServise.Object, null, _genreService.Object, _platformTypeService.Object);
            CommentViewModel model = new CommentViewModel() { Body = "body", Name = "Name", GameKey = "key" };

            //act
            controller.ViewData.ModelState.AddModelError("body", "empty");
            var result = controller.NewComment(model) as ViewResult;

            //arrange
            Assert.IsNotNull(result);
            Assert.AreEqual(1, controller.ViewData.ModelState.Count);
            Assert.IsInstanceOfType(result.Model, typeof(GameCommentsViewModel));
        }
コード例 #3
0
        public void Test_NewComment_Return_Right_Number_Of_Comments()
        {
            //arrange
            GameController controller = new GameController(_gameService.Object, _commentServise.Object, null, _genreService.Object, _platformTypeService.Object);
            CommentViewModel model = new CommentViewModel() { Body = "body", Name = "Name", GameKey = "key" };

            //act
            controller.ViewData.ModelState.AddModelError("body", "empty");
            var result = controller.NewComment(model) as ViewResult;

            //arrange
            Assert.AreEqual(1, (result.Model as GameCommentsViewModel).Comments.Count());
        }
コード例 #4
0
        public void Test_NewComment_Call_AddCommentToGame()
        {
            //arrange
            GameController controller = new GameController(_gameService.Object, _commentServise.Object, null, _genreService.Object, _platformTypeService.Object);
            CommentViewModel model = new CommentViewModel() {Body = "body", Name = "Name", GameKey = "key"};

            //act
            var result = controller.NewComment(model);

            //arrange
            _commentServise.Verify(s => s.AddCommentToGame(It.IsAny<CommentDTO>(), It.IsAny<GameDTO>()), Times.Once());
        }
コード例 #5
0
 /// <summary>
 /// Add parent for comment with quote
 /// </summary>
 /// <param name="comments">Comments source</param>
 /// <param name="parent">Parent to add</param>
 private void AddParrentForQuote(IEnumerable<CommentViewModel> comments,
     CommentViewModel parent)
 {
     foreach (var childComment in comments)
     {
         if (childComment.IsWithQuote)
             childComment.ParentComment = parent;
         if (childComment.ChildComments != null && childComment.ChildComments.Any())
             AddParrentForQuote(childComment.ChildComments, childComment);
     }
 }
コード例 #6
0
 public ActionResult NewComment( CommentViewModel model )
 {
     if (ModelState.IsValid)
     {
         GameDTO game = _gameService.GetGameByKey(model.GameKey);
         _commentService.AddCommentToGame(Mapper.Map<CommentViewModel, CommentDTO>(model), game);
         return RedirectToAction("Comments", new { key = model.GameKey });
     }
     var Comments = _commentService.CommentsAttachedToGame(model.GameKey)
         .Select(Mapper.Map<CommentDTO, CommentViewModel>)
         .ToList();
     GameCommentsViewModel gameComments = new GameCommentsViewModel {Comments = Comments, CommentToAdd = model};
     return View("Comments", gameComments);
 }