示例#1
0
        public void EditPost_ShouldHaveNewDetails()
        {
            var p = new Post();
            string postTitle = "Some Title To Be Edited";
            p.Slug = postTitle;
            p.Title = postTitle;
            p.Body = "Post that will be edited";
            p.Tags = new List<Tag> { new Tag { Name = "A" }, new Tag { Name = "B" } };
            p.Published = new DateTime(2005, 12, 12);

            var contentService = ObjectFactory.GetInstance<IContentService>();
            contentService.SavePost(p);

            Post retrievedPost = contentService.GetPostWithSlug(postTitle);

            int postid = retrievedPost.Id;

            var updatedPost = new Post();
            string updatedTitle = "UpdatedTitle";
            updatedPost.Slug = updatedTitle;
            updatedPost.Title = updatedTitle;
            updatedPost.Body = "Updated body";
            updatedPost.Tags = new List<Tag> { new Tag { Name = "updated tag" } };
            updatedPost.Published = new DateTime(2006, 1, 1);

            contentService.UpdatePost(postid, updatedPost);

            Post retrievedUpdatedPost = contentService.GetPostWithSlug(updatedTitle);
            Post originalPost = contentService.GetPostWithSlug(postTitle);

            Assert.IsNull(originalPost);
            Assert.IsNotNull(retrievedUpdatedPost);
        }
示例#2
0
        public void AddTwoPostsWithOverlappingTags_ShouldShowDistinctTags()
        {
            var p = new Post();
            string postTitle = "Some Title";
            p.Slug = postTitle;
            p.Title = postTitle;
            p.Body = "Some body";
            p.Tags = new List<Tag> { new Tag { Name = "A" }, new Tag { Name = "B" } };
            p.Published = new DateTime(2005, 12, 12);

            var p2 = new Post();
            string postTitle2 = "Some Title2";
            p2.Slug = postTitle2;
            p2.Title = postTitle2;
            p2.Body = "Some body2";
            p2.Tags = new List<Tag> { new Tag { Name = "B" }, new Tag { Name = "A" }, new Tag { Name = "D" }, new Tag { Name = "C" } };
            p2.Published = new DateTime(2006, 12, 12);

            IContentService contentService = ObjectFactory.GetInstance<IContentService>();
            contentService.SavePost(p2);
            contentService.SavePost(p);

            IEnumerable<Tag> tags = contentService.GetAllTags();

            Assert.IsTrue(tags.Count() == 4);
        }
示例#3
0
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var form = controllerContext.HttpContext.Request.Form;

            var post = new Post();

            post.Title = form["Title"];
            post.Body = form["Body"];
            post.IsPage = Convert.ToBoolean(form.GetValues("IsPage")[0]);
            post.Published = Convert.ToDateTime(form["Published"]);
            if (form["Id"] != null && !form["Id"].StartsWith("0000000"))
            {
                post.Id = Convert.ToInt32(form["Id"]);
            }

            if (form["Tags"] != null)
            {
                post.Tags = new List<Tag>();
                string []tags = form["Tags"].Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
                if (tags.HasData())
                {
                    foreach (var t in tags)
                        post.Tags.Add(new Tag{Name = t});
                }
            }

            return post;
        }
示例#4
0
        public SyndicationItem ConvertPostToSyndicationItem(Post post)
        {
            if (post == null) return null;

            SyndicationItem syndicationItem = new SyndicationItem(post.Title, post.Body, new Uri(_siteRoot + post.Slug))
            {
                PublishDate = post.Published,
                Title = new TextSyndicationContent(post.Title ?? string.Empty)
            };

            return syndicationItem;
        }
示例#5
0
        public void AddPostWithTags()
        {
            var p = new Post();
            string postTitle = "Some Title";
            p.Slug = postTitle;
            p.Title = postTitle;
            p.Body = "Some body";
            p.Tags = new List<Tag> {new Tag{Name = "A"}, new Tag{Name = "B"}};
            p.Published = new DateTime(2005, 12, 12);

            var contentService = ObjectFactory.GetInstance<IContentService>();
            contentService.SavePost(p);

            Post retrievedPost = contentService.GetPostWithSlug(postTitle);

            Assert.IsTrue(retrievedPost.Tags.Count == 2);
        }
示例#6
0
        public void UpdatePost(int postid, Post post)
        {
            var existingPost = GetPost(postid);
            existingPost.Author = post.Author;
            existingPost.Body = post.Body;
            existingPost.Published = post.Published;
            existingPost.Slug = post.Slug;
            existingPost.Tags = post.Tags ?? existingPost.Tags;
            existingPost.Title = post.Title;

            PostRepository.SavePost(existingPost);
        }
示例#7
0
        public void SavePost(Post post)
        {
            if (post == null) return;

            if (post.Tags.HasData())
            {
                IEnumerable<Tag> tagsThatAlreadyExist = TagRepository.SearchForTags(post.Tags);

                var tagsToReplace = (from newTag in post.Tags
                                     join t in tagsThatAlreadyExist on newTag.Name equals t.Name
                                     select newTag).ToList();

                foreach (Tag t in tagsToReplace)
                {
                    post.Tags.Remove(t);
                }

                tagsThatAlreadyExist.ToList().ForEach(tagThatExists => post.Tags.Add(tagThatExists));
            }

            //When testing the context doesn't have all this user info.  Could be mocked but isn't yet);
            if (post.Author == null && Context != null && Context.User != null && Context.User.Identity.Name != null)
            {
                post.Author = MembershipService.GetUser(Context.User.Identity.Name);
            }

            PostRepository.SavePost(post);
        }
示例#8
0
 public IList<Comment> GetApprovedCommentsForPost(Post post)
 {
     return CommentRepository.GetApprovedCommentsForPost(post);
 }
示例#9
0
 public bool DeletePost(Post p)
 {
     CUDQuery query = session => session.Delete(p);
     return QueryExecutor.UpdateDelete(query);
 }
示例#10
0
 public void SavePost(Post post)
 {
     CUDQuery query = session => session.SaveOrUpdate(post);
     QueryExecutor.UpdateDelete(query);
 }
示例#11
0
 public IList<Comment> GetApprovedCommentsForPost(Post post)
 {
     return GetApprovedCommentsForPost(post.Id);
 }
示例#12
0
 public virtual ActionResult Save(Post p)
 {
     ContentService.SavePost(p);
     return RedirectToRoute(RouteNames.Posts);
 }
示例#13
0
 private ActionResult CreateEditView(Post p)
 {
     return View("Create", p);
 }