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
        static void ImportCategories()
        {
            Write("Deleting Categories");
            //delete existing
            Category.Delete(x => x.CategoryID > 0);
            //pull the WP tags
            var query = from t in wp_term.All()
                        join tt in wp_term_taxonomy.All() on t.term_id equals tt.term_id
                        where tt.taxonomy == "category"
                        select t;

            foreach (var term in query) {
                //add the tag to the DB
                Write("Adding category " + term);
                var c = new Category();
                c.Description = term.name;
                c.Slug = term.slug;
                c.Add();
            }
            Write("Finished importing categories **************************");
        }
Beispiel #3
0
        /// <summary>
        /// pulls the data for use on the home page
        /// </summary>
        /// <returns></returns>
        public PostViewModel GetHomePage()
        {
            var totalPosts = _repo.All<Post>().Count();
            var totalComments = _repo.All<Comment>().Count();

            var featured=(from p in _repo.All<Post>()
                       where p.PublishedAt <= DateTime.Now && p.Status==PostStatus.Published
                       select p);

            var subsonicCategory=new Category("SubSonic");
            var subsonic = _repo.GetAssociated<Category, Post>(subsonicCategory);

            var opinionCat = new Category("Opinion");
            var opinion = _repo.GetAssociated<Category, Post>(opinionCat);

            var recentComments = (from c in _repo.All<Comment>()
                                  orderby c.CreatedAt descending
                                  where c.Status==CommentStatus.Approved
                                  select c);

            return new PostViewModel(totalPosts, totalComments, featured,
                subsonic, opinion, recentComments);
        }
Beispiel #4
0
 public static void Setup(int testItems)
 {
     SetTestRepo();
     for(int i=0;i<testItems;i++){
         Category item=new Category();
         _testRepo._items.Add(item);
     }
 }
Beispiel #5
0
 public static void Setup(Category item)
 {
     SetTestRepo();
     _testRepo._items.Add(item);
 }