public Comment UpdateComment(Comment comment)
 {
     using (ITransaction transaction = Session.BeginTransaction())
     {
         Session.Update(comment);
         transaction.Commit();
     }
     return comment;
 }
        public void DeleteComment(Comment comment)
        {
            if (comment == null) throw new ArgumentNullException("comment");

            if(comment.Id <=0)
                throw new ArgumentException("comment entity is not valid");

            commentRepository.DeleteComment(comment);
        }
 public void UndeleteComment(Comment comment)
 {
     using (ITransaction transaction = Session.BeginTransaction())
     {
         comment.Deleted = 0;
         Session.Update(comment);
         transaction.Commit();
     }
 }
        public void AddComment_when_comment_has_post_as_null_it_should_throw_ArgumentException()
        {
            //Arrange
            Comment comment = new Comment();
            comment.Post = null;

            //Act
            service.AddComment(comment);

            //Assert
            commentRepositoryMock.Verify(x=>x.AddComment(comment), Times.Never());
        }
        public Comment AddComment(Comment comment, int postId)
        {
            if(postId <= 0)
                throw new ArgumentOutOfRangeException("comment", postId, "should be greater than zero");

            Post post = postRepository.GetPostById(postId);

            if (post == null)
                throw new ArgumentOutOfRangeException("postId", postId, "There is no post with that id");

            comment.Post = post;
            return AddComment(comment);
        }
        public Comment AddComment(Comment comment)
        {
            if (comment == null) throw new ArgumentNullException("comment");

            if (comment.User == null)
                throw new ArgumentException("All posted comments must have a user attached");

            if (comment.Post == null)
                throw new ArgumentException("All comments added must be attached to a post");

            if(comment.Post.Id <= 0)
                throw  new ArgumentException("All comments must have a valid existing post attached to it");

            SetupCommentDefaults(comment);

            commentRepository.AddComment(comment);

            return comment;
        }
        protected void SetupCommentDefaults(Comment comment)
        {
            comment.Id = 0;
            comment.Date = DateTime.Now;
            comment.Approved = false;
            comment.Deleted = 0;

            comment.User = userServices.GetNewOrExistingVisitor(comment.User);
        }
        private void SetupMocks()
        {
            var serviceMock = new MoqAutoMocker<CommentServices>();

            commentRepositoryMock = Mock.Get(serviceMock.Get<ICommentRepository>());
            appConfigProviderMock = Mock.Get(serviceMock.Get<IAppConfigProvider>());
            userRepository = Mock.Get(serviceMock.Get<IUserRepository>());
            userServicesMock = Mock.Get(serviceMock.Get<UserServices>());

            SetupUserRepositoryMocks();
            SetupCommentRepositoryMocks();
            SetupUserServiceMocks();
            SetupAppConfigMocks();

            service = serviceMock.ClassUnderTest;

            _AddedComment = null;
            user = new User{DateCreated = DateTime.Now, Email = "*****@*****.**", Name = "testuser"};
        }
 private void SetupCommentRepositoryMocks()
 {
     commentRepositoryMock
         .Setup(x => x.AddComment(It.IsAny<Comment>()))
         .Returns<Comment>(y =>
                               {
                                   _AddedComment = y;
                                   return y;
                               });
 }
 private Comment GetNewComment()
 {
     Comment comment = new Comment();
     comment.Approved = false;
     comment.Date = DateTime.Now;
     comment.Id = 0;
     comment.Post = new Post{Id=6};
     comment.Text = "New test comment";
     comment.AddUser(user);
     return comment;
 }
示例#11
0
        private Comment GetComment(CommentDetails commentDetails)
        {
            Comment comment = new Comment { Text = commentDetails.Text };
            User user = new User { Email = commentDetails.UserEmail, Name = commentDetails.UserName, WebSite = commentDetails.UserWebSite };
            comment.User = user;

            return comment;
        }