Exemple #1
0
        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());
        }
Exemple #2
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         Tags_Post item=new Tags_Post();
         _testRepo._items.Add(item);
     }
 }
Exemple #3
0
 public static void Setup(Tags_Post item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }
Exemple #4
0
        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 **************************");
        }