Пример #1
0
        public void Write_Should_Save_Comment()
        {
            FunctionalTestHelper.CreateAutomapperMap();
            FunctionalTestHelper.CreateAccountAndBlog(_dbContext);
            FunctionalTestHelper.CreateOnePost(_dbContext);
            FunctionalTestHelper.CreateOneCommenter(_dbContext);

            _controller = new CommentController();

            var commentInput = new CommentInput
                                   {
                                       Content = "content",
                                       Email = FunctionalTestHelper.CommenterEmail,
                                       Name = FunctionalTestHelper.CommenterName,
                                   };
            var result = _controller.Write(commentInput, 1) as RedirectToRouteResult;

            result.RouteValues["controller"].ShouldEqual("Post");
            result.RouteValues["action"].ShouldEqual("Detail");
            result.RouteValues["id"].ShouldEqual(1);

            _dbContext.Comments.Count().ShouldEqual(1);
            var comment = _dbContext.Comments.FirstOrDefault();
            comment.Content.ShouldEqual("content");
            comment.Commenter.Email.ShouldEqual(FunctionalTestHelper.CommenterEmail);
            comment.Commenter.Name.ShouldEqual(FunctionalTestHelper.CommenterName);
        }
Пример #2
0
 private Commenter GetCommenter(CommentInput input)
 {
     if (!string.IsNullOrWhiteSpace(input.OpenId) && DbContext.Commenters.Count(c => c.OpenId == input.OpenId) > 0)
     {
         // this means that user changed email and user name in comment input form that has a openid value as hidden field
         // that is, user does not want use openid, so that openid will not be saved
         return new Commenter
         {
             Email = input.Email,
             Name = input.Name,
             Url = input.Url
         };
     }
     else
     {
         return new Commenter
         {
             Email = input.Email,
             Name = input.Name,
             OpenId = input.OpenId,
             Url = input.Url
         };
     }
 }