public void Ctor_SetsAND_BlogPostRepository_Property_To_blogPostRepository_Parameter_LookupRepository_Property_To_lookupRepository_Parameter_()
        {
            var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
            var mockedLookupRepository = new Mock<ILookupRepository>();

            var blogPostDeleter = new BlogPostDeleter(mockedBlogPostRepository.Object, mockedLookupRepository.Object);

            blogPostDeleter.BlogPostRepository.ShouldEqual(mockedBlogPostRepository.Object);
            blogPostDeleter.LookupRepository.ShouldEqual(mockedLookupRepository.Object);
        }
        public void MarkAsDeleted_GIVEN_AuthorRepository_Has_No_Users_WHEN_userId_Is_1_THEN_Throws_UnknownUserException()
        {
            const int UserId = 1;

            BlogPost savedBlogPost = null;

            var imageReference1 = GetImageReference();
            var post = new BlogPost("ABC", "description", "fullText", imageReference1, DateTime.Now, new BlogUser());

            var mockedLookupRepository = new Mock<ILookupRepository>();
            mockedLookupRepository.Setup(r => r.LoadForId<BlogUser>(It.IsAny<object>())).Returns(null as BlogUser);

            var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
            mockedBlogPostRepository.Setup(r => r.SaveOrUpdate(It.IsAny<BlogPost>())).Callback<BlogPost>(bp => savedBlogPost = bp);

            var blogPostDeleter = new BlogPostDeleter(mockedBlogPostRepository.Object, mockedLookupRepository.Object);

            blogPostDeleter.MarkAsDeleted(post, UserId);
        }
        public void MarkAsDeleted_GIVEN_Author_With_Id_1_Exists_In_AuthorRepository_WHEN_userId_Is_1_THEN_Saves_BlogPost_With_DeletedByUser_As_Author_With_Id_1()
        {
            const int UserId = 1;

            BlogPost savedBlogPost = null;

            var imageReference1 = GetImageReference();
            var post = new BlogPost("ABC", "description", "fullText", imageReference1, DateTime.Now, new BlogUser());

            var deletionUser = new BlogUser { Id = UserId, Forenames = "Joe", Surname = "Blogs" };

            var mockedLookupRepository = new Mock<ILookupRepository>();
            mockedLookupRepository.Setup(r => r.LoadForId<BlogUser>(It.IsAny<object>())).Returns(deletionUser);

            var mockedBlogPostRepository = new Mock<IBlogPostRepository>();
            mockedBlogPostRepository.Setup(r => r.SaveOrUpdate(It.IsAny<BlogPost>())).Callback<BlogPost>(bp => savedBlogPost = bp);

            var blogPostDeleter = new BlogPostDeleter(mockedBlogPostRepository.Object, mockedLookupRepository.Object);

            blogPostDeleter.MarkAsDeleted(post, UserId);

            savedBlogPost.ShouldNotBeNull();
            savedBlogPost.DeletedByUser.ShouldEqual(deletionUser);
        }
        public ActionResult Delete(int blogPostId)
        {
            BlogPost blogPost = BlogPostRepository.LoadFullArticle(blogPostId); //nHibernate won't update objects with lazy load properties

            if (blogPost != null)
            {
                var blogPostDeleter = new BlogPostDeleter(BlogPostRepository, LookupRepository);
                blogPostDeleter.MarkAsDeleted(blogPost, JumbleblocksPrincipal.Identity.UserId.Value);

                ViewData.Model = new DeletedModel { BlogPostId = blogPost.Id.Value, Title = blogPost.Title };
                return View("Deleted");
            }

            return Redirect(Request.UrlReferrer.AbsoluteUri);
        }