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