public void PostsByTag_Should_Return_Related_Posts() { var posts = new List<Post>(); var tags = new List<Tag>(); var rel = new List<Tags_Post>(); var post = new Post(); post.PostID = 1; post.Title = "Tagged Post"; posts.Add(post); var tag = new Tag(); tag.TagID = 1; tag.Description = "tag"; tags.Add(tag); var tp = new Tags_Post(); tp.PostID = 1; tp.TagID = 1; rel.Add(tp); //setup SubSonic Post.Setup(posts); Tag.Setup(tags); Tags_Post.Setup(rel); var result = Post.PostsByTags("tag"); Assert.Equal(1,result.Count()); }
public void PostsByCategory_Should_Return_Related_Posts() { var posts = new List<Post>(); var cats = new List<Category>(); var rel = new List<Categories_Post>(); var post = new Post(); post.PostID = 1; post.Title = "Tagged Post"; posts.Add(post); var cat = new Category(); cat.CategoryID = 1; cat.Description = "category"; cats.Add(cat); var cp = new Categories_Post(); cp.PostID = 1; cp.CategoryID = 1; rel.Add(cp); //setup SubSonic Post.Setup(posts); Category.Setup(cats); Categories_Post.Setup(rel); var result = Post.PostsByCategory("category"); Assert.Equal(1, result.Count()); }
public PostViewModel(Post selectedPost, IEnumerable<Post> related, int totalPosts, int totalComments) { TotalPosts = totalPosts; TotalComments = totalComments; SelectedPost = selectedPost; if (related != null) Related = related.Take(5).ToList(); else Related = new List<Post>(); }
public static string CreateSummary(Post post) { string result = post.Body; if (post.Body.Contains("<!--more-->")) { result= post.Body.Chop("<!--more-->"); } else { var entry = post.Body.StripHTML(); //regex on the sentences and return the first 2 var reg = new Regex(@"[^.?!]+[.?!]"); var matches = reg.Matches(entry); if (matches.Count > 1) { result = matches[0].Value + matches[1].Value; } else if (matches.Count > 0) { result = matches[0].Value; } } return result; }
public void PublishedPosts_Should_Return_Posts_With_PublishDate_Less_Than_Today() { var posts = new List<Post>(); var oldPost = new Post(); oldPost.Title = "Old Post"; oldPost.PublishedOn = DateTime.Now.AddDays(-3); var newPost = new Post(); newPost.Title = "New Post"; newPost.PublishedOn = DateTime.Now.AddDays(3); posts.Add(oldPost); posts.Add(newPost); //Set up SubSonic Post.Setup(posts); var result = Post.Published(); Assert.Equal(1,result.Count()); Assert.Equal("Old Post", result.First().Title); }
public PostView(Post post) { Slug = post.Slug; Title = post.Title; Body = post.Body; Author = "Rob Conery"; PublishedAt = post.PublishedOn; CommentCount = post.CommentCount; Summary = post.Excerpt; }
static void ImportPosts() { Write("Deleting Posts, Comments and Tag/Category associations"); //delete existing Tags_Post.Delete(x => x.PostID > 0); Categories_Post.Delete(x => x.PostID > 0); Comment.Delete(x=>x.CommentID>0); Post.Delete(x => x.PostID > 0); var posts = wp_post.All().Where(x => x.post_status == "publish"); foreach (var post in posts){ Write("Adding Post "+post.post_title); Post p=new Post(); p.PostID = (int)post.ID; p.Title = post.post_title; p.Author = "Rob Conery"; p.PublishedOn = post.post_date; p.CreatedOn = post.post_date; p.ModifiedOn = post.post_modified; p.Slug = post.post_name; p.Body = post.post_content; p.Excerpt = post.Excerpt; p.CommentCount = wp_comment.All().Count(x => x.comment_post_ID == post.ID); p.IsPublished = true; p.Add(); //get the tags for this post var tags = (from t in wp_term.All() join tt in wp_term_taxonomy.All() on t.term_id equals tt.term_id join tr in wp_term_relationship.All() on tt.term_taxonomy_id equals tr.term_taxonomy_id where tt.taxonomy == "post_tag" && tr.object_id==post.ID select t).ToList(); for (int i = 0; i < tags.Count; i++){ Write("Setting tag " + tags[i].name); p.Tags += tags[i].name; if (i + 1 < tags.Count) p.Tags += ","; //set the association var t = Tag.SingleOrDefault(x => x.Description == tags[i].name); if(t!=null){ var tp=new Tags_Post(); tp.PostID = p.PostID; tp.TagID = t.TagID; tp.Add(); } } //get the categories for this post var cats = (from t in wp_term.All() join tt in wp_term_taxonomy.All() on t.term_id equals tt.term_id join tr in wp_term_relationship.All() on tt.term_taxonomy_id equals tr.term_taxonomy_id where tt.taxonomy == "category" && tr.object_id == post.ID select t).ToList(); for (int i = 0; i < cats.Count; i++) { Write("Setting category " + cats[i].name); //set the association var c = Category.SingleOrDefault(x => x.Description == cats[i].name); if (c != null) { var cp = new Categories_Post(); cp.PostID = p.PostID; cp.CategoryID = c.CategoryID; cp.Add(); } } //import the comments ImportComments(post.ID); } Write("Finished importing Posts **************************"); }